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

Storable( Double size not compatible in Storable) compatible)

by kaushal_k1 (Novice)
on Jan 07, 2011 at 18:04 UTC ( #881140=perlquestion: print w/ replies, xml ) Need Help??
kaushal_k1 has asked for the wisdom of the Perl Monks concerning the following question:

I have a DB file which was created in perl5.8 which contains hash (values of which have been freeze(). ) When i try to thaw it in perl5.10 it errpors out saying Double size is not comparable in Storable.pm. Looked at the XS code in Storable module, found that it fails because sizeof(double) is compared with sizeof(long double). How do I make thaw in perl5.10 work with a scalar freeze 'd in perl5.10. The problem is I can't rebuild database files in perl5.10 as it is large in number.

Comment on Storable( Double size not compatible in Storable) compatible)
Re: Storable( Double size not compatible in Storable) compatible)
by Anonymous Monk on Jan 07, 2011 at 19:43 UTC

    A straightforward workaround is to load your records with the 5.8 version of storable, then write them back with the 5.10 version to migrate your database to the new format.

Re: Storable( Double size not compatible in Storable) compatible)
by scorpio17 (Monsignor) on Jan 07, 2011 at 19:49 UTC

    Here's one solution: find a system with perl5.8 installed. copy your DB file to that system, and unthaw it there. Dump the raw data, copy it to the Perl5.10 system, then import it back into the DB. Storable is not very portable. I've been burned in the past because I upgraded Storable, and it wasn't backwards compatible with the older version. If you need the data to be portable across multiple systems, forget it. Switch to a different serializer. I like YAML. Also, checkout Data::Serializer.

Re: Storable( Double size not compatible in Storable) compatible)
by BrowserUk (Pope) on Jan 07, 2011 at 20:06 UTC
    Looked at the XS code in Storable module, found that it fails because sizeof(double) is compared with sizeof(long double)

    This sounds like a compilation or configuration error to me.

    As far as I am aware, the format of perl's native doubles didn't change between versions 5.8.x and 5.10.x. They remain 64-bit IEEE 754 format not the 80-bit long double format. I believe this is also true on 64-bit builds.

    Did you build your 5.10 perl yourself? If so, it may be that all you need to do is reconfigure and rebuild to fix the problem.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      it may be that all you need to do is reconfigure and rebuild to fix the problem.

      Yes, it's a configuration option: -Duselongdouble  (or -Uuselongdouble to explicitly undefine/disable).

        If it is configurable, Storable ought to be able to handle both and the conversion between the two.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Storable( Double size not compatible in Storable) compatible)
by sundialsvc4 (Monsignor) on Jan 08, 2011 at 16:59 UTC

    Actually, for what it’s worth, I gave up on Storable quite some time ago.   JSON works just about as well, and it has the advantage of being human-readable.   I simply had one too many cases of things that I had frozen that I could not reliably thaw.   What we really need is 100% reliability, not speed or cleverness.

      What we really need is 100% reliability, not speed or cleverness.

      Is that the royal we, or do you presume to speak for all application writers everywhere?

        I think sundialsvc4 should presume to speak for all applications. The only core module we've got to serialize data structures is non transportable and therefore undependable. Core modules shouldn't be a gamble.

        I've been burned myself by 'fozen' data that wouldn't thaw after being transfered to another machine with a different version of Storable. A simple perl update could leave you with a database of unusable data, or a backup file that can no longer be recovered, or in my case it was a move to another server (with a different versions of everything). I'm not going to risk my application like that (again).

        So having learned by lesson I avoid Storable like the plague. Now I 'freeze' data with Data::Dumper (which is core) and 'thaw' with eval. It's messy and awkward and I'm sure no where near as efficient as free/thaw but at least the serialized result is guaranteed to be readable by any version of Perl on any system the data may end up on (or moved to).

        Before it was ever introduced to core, Storable should have been prepared for a future of new features and formats. From the very first 'version change' it should have been purposely defaulted to the most basic universally recognized serialized data format (first version) with caveats to programmers wishing to take advantage of newer features. I would be using it today if I could expect consistent behaviour between versions but as it is I can't rely on it and I can't recommend it. The genie is out of the bottle, you can't fix Storable now.

        Storable has too high a price to pay for anything but fleetingly temporary data. In other words, data that probably shouldn't be 'stored' in the first place. In my books that makes the module a complete fail for the purpose it is (generally) expected to serve.

Re: Storable( Double size not compatible in Storable) compatible)
by Anonymous Monk on Jan 09, 2011 at 02:33 UTC
    Use the portable version, nfreeze/nthaw?
      I don't think its portable between versions of Storable. Its portable on network(byte order).
Re: Storable( Double size not compatible in Storable) compatible)
by kaushal_k1 (Novice) on Jan 10, 2011 at 13:43 UTC
    I could not find a good way out . I am changing code to Dumper/eval. Thanks for all the suggestions.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://881140]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2014-07-29 10:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (213 votes), past polls