Python::Serialise::Pickle - a file for reading and writing pickled Python files
use Python::Serialise::Pickle; my $pr = Python::Serialise::Pickle->new("file/for/reading"); while (my $data = $pr->load()) { print Dumper $data; } my $pw = Python::Serialise::Pickle->new(">file/for/writing"); $pw->dump(['a' 'list']); $pw->dump("a string"); $pw->dump(42); $pw->dump({'a'=>'hash'}); $pw->close();
Pickling is a method of serialising files in Python (another method, Marshalling, is also available).
This module is an attempt to write a pure Perl implementation of the algorithm.
Open a file for reading or writing. Can take any arguments that IO::File can.
IO::File
Returns the next data structure from the pickle file or undef.
Takes a ref to an array or a hash or a number or string and pickles it.
Structures may be nested.
Closes the current file.
Almost certainly lots and lots.
At the moment we don't deal with serialised objects very well. Should probably just take or return a Python::Serialise::Pickle::Object object.
Similar to Perl's undef but an object. At the moment we deal with it badly because if we returned undef then that would signify the end of the Pickle file.
Should probably be returned as a special object or something.
There's no testing for longs
Ditto
Dictionaries are the Python equivalent of hashes. This module can deal with most nested dictionaries but, for some reason, this one :
a={'a':['two',{'goof':'foo', 'a':[1,2,3]}]}
causes it to fail.
Chnaging it slightly starts it working again.
This is entirely my fault
You could always dump the data structure out as YAML in Python and then read it back in with YAML in Perl.
Simon Wistow <simon@thegestalt.org>
(c) 2003 Simon Wistow
Distributed under the same terms as Perl itself.
This software is under no warranty and will probably ruin your life, kill your friends, burn your house and bring about the apocalypse.
http://www.python.org, YAML, IO::File and the RESOURCES file in this distribution.
To install Python::Serialise::Pickle, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Python::Serialise::Pickle
CPAN shell
perl -MCPAN -e shell install Python::Serialise::Pickle
For more information on module installation, please visit the detailed CPAN module installation guide.