Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

convert 32-bit storables to 64-bit

by Wiggins (Hermit)
on Nov 06, 2014 at 13:52 UTC ( [id://1106367]=perlquestion: print w/replies, xml ) Need Help??

Wiggins has asked for the wisdom of the Perl Monks concerning the following question:

I am asking if there is some obscure tool that will convert 'storables' between 32-bit and 64-bit formats?

I am building an ISAM (Indexed Sequential Access Method) pair of data structures, and then 'storing' them to be reloaded and used during operations. The data portion is a hash keyed on integers, containing arrays of 3 elements. I would like to convert them , rather than stand up a 32-bit OS and a 64-bit OS and shuffle the code between them.

p.s. I use only core packages for portability.

It is always better to have seen your target for yourself, rather than depend upon someone else's description.

Replies are listed 'Best First'.
Re: convert 32-bit storables to 64-bit
by Corion (Patriarch) on Nov 06, 2014 at 14:02 UTC

    No. Basically, Storable can only load files created with the same architecture and version of Perl.

    You should consider a different serialization format. For example, JSON or maybe Sereal. If you have the CPU and disk to spare, Data::Dumper can also produce output that is highly likely to be loadable on a different machine, architecture and version of Perl.

      Hi Corion,

      may I cite the documentation of Storable:

      Surprisingly, the routines to be called are named freeze and thaw. If you wish to send out the frozen scalar to another machine, use nfreeze instead to get a portable image.

      We work with nfreeze a long time now without any known hassle. But, yes, using freeze crossing architecture boundaries does make problems.

      Regards
      McA

        Thank you for prompting me to (re)read the Storable documentation!

        It seems that Storable got much better especially with forward compatibility since I last looked closely at it.

        I think is the same for nstore, or I have to rewrite my portable project??!? ;=)


        L*
        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: convert 32-bit storables to 64-bit
by choroba (Cardinal) on Nov 06, 2014 at 14:01 UTC
    p.s. I use only core packages for portability.
    Data::Dumper then? For portability, I'd use YAML or JSON (or even Sereal), so it seems, core ≠ portability.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      My meaning of 'portable' is that my code runs on any system that has a basic Perl install, without having to know how to install Perl packages.

      It is always better to have seen your target for yourself, rather than depend upon someone else's description.

        So you want a one-liner?
Re: convert 32-bit storables to 64-bit
by Eily (Monsignor) on Nov 06, 2014 at 14:23 UTC

    I'm not sure I got what you were saying alright, but instead of whatever solution you are using right now to store and read your data, pack might just work.

    use Data::Dumper; # Input data my %data = ( 1 => [qw/I don't know/], 2 => [qw/what to use/], 3 => [qw +/as values !/] ); # Repeat multiple times: # A signed 32 bit integer followed by three null terminated strings my $pattern = "(l(Z*)3)*"; # Encoding my $packed = pack $pattern, map { $_, @{$data{$_}} } keys %data; # Decoding my @unpacked = unpack $pattern, $packed; my ($key, @values, %out); $out{$key} = [@values] while (($key, @values) = splice @unpacked, 0, 4 +); print Dumper \%out;

    Edit: well, now that I think of it, Data::Dumper would be a far easier solution to store data in an architecture independant way. I guess I have been working with pack too much lately ^^".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1106367]
Approved by GotToBTru
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-25 20:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found