3

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

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
Rakesh
  • 5,793
  • 8
  • 36
  • 37

4 Answers4

11

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
  • 42,082
  • 9
  • 61
  • 86
5

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
  • 23,338
  • 31
  • 90
  • 128
4

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
  • 122,029
  • 33
  • 303
  • 309
  • 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 Feb 20 '09 at 17:13
  • 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 Feb 20 '09 at 17:36
  • 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 Feb 20 '09 at 18:45
  • 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 Feb 20 '09 at 19:06
  • Ah, I see. Well, glad to be of service, then. I guess it all worked out in the end. – chaos Feb 20 '09 at 19:15
4

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
  • 29,660
  • 2
  • 47
  • 102
  • If you're going to exec Perl for every request, why would you be using PHP to begin with? – jrockway Feb 20 '09 at 19:37
  • 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 Feb 20 '09 at 23:31