views:

543

answers:

4

Can a PHP script unserialize a Storable file created with Perl?

+11  A: 

No, but you can dump PHP-readable data from Perl with PHP::Serialization. You also might want to pick something more standard, like YAML or JSON. Pretty much any language can understand those.

jrockway
Well, you could do it if you rewrote Storable as a PHP library, couldn't you? :)
brian d foy
That's what I'm sayin'.
chaos
Good luck mapping Storable's concepts onto PHP (like blessed references).
jrockway
+3  A: 

You could use JSON as a lingua-franca between the two languages, I suggest JSON::XS on the Perl side (with subroutines implemented in C/C++) for performances, then you can read back (in PHP) the JSON with this extension.

tunnuz
+4  A: 

PHP being Turing-complete and all, the answer isn't really "no" so much as "not natively or with any well-known public module".

chaos
YAML does the trick, and is more or less widely known. -1
Axeman
Um... no. Read the question. YAML is a solution for transferring serialized data between PHP and Perl; it is not a solution for *reading serialized data from Perl's Storable module into PHP*.
chaos
Okay, you weren't being helpful with the early kick-out, then. BTW, thanks for all the downvotes with posts that each one contains about 3-times more helpful detail than your early kick-out.)
Axeman
This is faintly ridiculous, since it's right there in front of you that I wrote my answer an hour after the other two. But I guess you've already demonstrated reading comprehension issues. I wrote what I wrote because the accepted answer's "no" isn't really true.
chaos
Early kick-out="Test. No? -> Done." Like a flowchart. Actually, my reading comprehension is fine--when I reread a source. By the time I read down the page, I had forgotten the actual context. You helped me realize that the question--as asked--hadn't been answered.
Axeman
Ah, I see. Well, glad to be of service, then. I guess it all worked out in the end.
chaos
+4  A: 

As chaos points out, you asked for Storable specifically, and so switching to YAML (or JSON) may be possible, but it may not. This might work to get it into YAML (or even JSON):

$output_format = 'YAML';
popen( "perl -MStorable -M${output_format}::Syck=Dump -e 'print Dump( retrieve( q{$storable_file_path} ))'", "r" );
Axeman
If you're going to exec Perl for every request, why would you be using PHP to begin with?
jrockway
Jon (rockway), who said anything about exec-ing it every request? You could substitute -MPHP::Serialization=serialize and print serialize( retrieve( ... )), you can fwrite that string to a file or but you'd still have to fread it, no matter what.
Axeman