I have a legacy database which contains simple data structures (no CODE refs thank goodness) that have been written using the nfreeze
method of the Storable
module in Perl.
Now I have a need to load this data into a Python application. Does anyone know of a Python implementation of Storable
's thaw
? Google hasn't helped me.
If it comes to it, I can reverse engineer the data format from the Storable source, but I'd prefer to avoid that fun if it's been done already.
To express in code: Given a Perl program like this:
#!/usr/bin/perl
use strict;
use warnings;
use MIME::Base64;
use Storable qw/nfreeze/;
my $data = {
'string' => 'something',
'arrayref' => [1, 2, 'three'],
'hashref' => {
'a' => 'b',
},
};
print encode_base64( nfreeze($data) );
I'm after a magic_function
such that this Python:
#!/usr/bin/env python
import base64
import pprint
import sys
def magic_function(frozen):
# A miracle happens
return thawed
if __name__ == '__main__':
frozen = base64.b64decode(sys.stdin.read())
data = magic_function(frozen)
pprint.pprint(data)
prints:
{'string': 'something', 'arrayref': [1, 2, 'three'], 'hashref': {'a': 'b'}}
when run against the output of the Perl program.
It's not immediately clear to me how far along this project is, but it appears to aim to do what you want:
https://pypi.org/project/storable/
If your first option doesn't work, another option would be to write a simple perl script to thaw the data, and then write it out in JSON or YAML or some format that you can easily work with in Python.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With