#!/usr/bin/perl -w use serialize; =pod This is a sample perl script to test the serialize.pm module. Once you run this script, take the output and paste it into "test.php" to see how PHP de-serializes this modules output =cut # Array to test serialization on my @j = (2,4,10,[11,12,13]); # Hash to test serialization on my %h = ( 1 => 'Yes', 0 => 'No', 'name' => "Scott Hurring", 'email' => "scott (at) hurring.com", 'age' => 21.85, 'null' => "NULL", 'numbers' => [1,2,3,4], 'music' => { 'doors' => 'Strange Days', 'numan' => 'Telekon'} ); print "Printing original hash\n"; dump_hash(\%h, []); print "-" x 40 ."\n\n"; print "Printing serialized hash\n"; my $sh = serialize(\%h); print "$sh\n\n"; print "-" x 40 ."\n\n"; print "Printing unserialized hash\n"; my $uh = unserialize($sh); dump_hash($uh, []); print "-" x 40 ."\n\n"; exit; print "-" x 80 ."\n\n"; print "Printing original hash\n"; dump_array(\@j, []); print "-" x 40 ."\n\n"; print "Printing serialized hash\n"; my $sj = serialize(\@j); print "$sj\n\n"; print "-" x 40 ."\n\n"; print "Printing unserialized hash\n"; my $uj = unserialize($sj); dump_hash($uj, []); print "-" x 40 ."\n\n"; exit; sub dump_hash { my ($hashref, $offset) = @_; foreach my $k (keys %{$hashref}) { print join ("",@$offset) . "$k = $$hashref{$k}\n"; if (ref($$hashref{$k}) =~ /hash/i) { push (@$offset, "\t"); &dump_hash($$hashref{$k}, $offset); pop @$offset; } } return 1; } sub dump_array { my ($arrayref, $offset) = @_; foreach my $k (@{$arrayref}) { print join ("",@$offset) . "$k\n"; if (ref($k) =~ /array/i) { push (@$offset, "\t"); &dump_array($k, $offset); pop @$offset; } } return 1; }