Perl implementation of PHP's native serialize() and unserialize() functions. Scott Hurring scott at hurring dot com http://hurring.com/ Please be nice and send bugfixes and code improvements to me. @version v0.91 @author Scott Hurring; scott at hurring dot com @copyright Copyright (c) 2005 Scott Hurring @license http://opensource.org/licenses/gpl-license.php GNU Public License Most recent version can be found at: http://hurring.com/code/perl/serialize/ ===================================================================== Unlike modules that make use of language-specific binary formats, the output of serialize() is an ASCII string, meaning you can easily manipulate it as you would any other string, i.e. sticking it into a URL, a database, a file, etc... Taken along with my python serialize implementation, this code will enable you to transfer data between PHP, Python, and Perl using PHP's data serialization format. To serialize: # serialize an array into a string my $serialized_string = serialize(\@data); # or... serialize a hash into a string my $serialized_string = serialize(\%data); To unserialize: # unserialize some string into python data $hash_ref = unserialize($serialized_string) PHP Serialization Format: NULL N; Boolean b:1; b:$data; Integer i:123; i:$data; Double d:1.23; d:$data; String s:5:"Hello" s:$length:"$data"; Array a:1:{i:1;i:2} a:$key_count:{$key;$value} $value can be any data type Supported Perl Types: Serializing: NULL (\0), int, double, string, hash, array Unserializing: NULL (\0), int, double, string, hash *array is unserialized as a hash, becuase PHP only has one array type "array()", which is analagous to Perl hash's. When you try to serialize a perl array, it's automagically converted into a hash with keys numbered from 0 up. Type Translation Table: (Perl) (serialize) (PHP) (unserialize) (Perl) NULL => NULL => NULL int => int => int double => double => double string => string => string hash => array => hash array => array => hash ==================================================================== Warning: This code comes with absolutely NO warranty... it is a quick hack that i sometimes work on in my spare time. This code may or may not melt-down your computer and give you nonsensical output. Please, do not use this code in a production enviornment until you've thoroughly tested it. =====================================================================