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

Greetings Brothers,

I'm writing a fairly simple system analysis script, where I would like to save a set of data to a file, and read it in on a new machine.

YAML would be my first choice. But for various reasons I would like to stick with core perl, if at all possible.

My understanding is that Storables are not necessarily portable between machines, even when using nstore.

I'm even contemplating just saving Data::Dumper output to a file, and then evaling that in on the new machine--but for some reason my mind rebels at that. Any ideas on a really good way to do this? Any input would be greatly appreciated!

  • Comment on Portable datastore formats in core perl?

Replies are listed 'Best First'.
Re: Portable datastore formats in core perl?
by BrowserUk (Patriarch) on Jul 28, 2010 at 22:19 UTC
    My understanding is that Storables are not necessarily portable between machines, even when using nstore.

    Care to elaborate on that. What have you heard and where?

    There are going to be some situations where portability isn't possible.

    1. Data packed with the latest version probably won't be portable to a machine running an ancient version.

      As perl (and the rest of the world) have adapted to new requirements (unicode for example), those adaptations inevitably break backwards compatibility. But ditto for any transfer format pre- and post-unicode support.

      If you use newer features--like coderefs; then portability will be restricted by the features used by that code. say won't work pre-5.10.x; but neither will Java5 code compile on a Java3 compiler.

    2. 64-bit integers won't port to a 32-bit machine.

      But even a text format file will have this problem. A 32-bit machine will bottle out trying to read a > 32-bit integer, even if it is formatted as text.

    3. The target machines will need to have the appropriate modules to support stored blessed refs.

      This wil be the same whether you use Storable, Yaml, or Data::Dumper.

    Often the solution to these types of problems is to consider what your portability requirements actually are, rather than seeking "universal portability". It's often a variation on YAGNI.


    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: Portable datastore formats in core perl?
by Generoso (Prior) on Jul 28, 2010 at 21:18 UTC

    If it is only data that you are trying to port form one machine to an other, I will suggest a simple coma delimited flat file.

    data1,data2,date,number,etc ....
    data1,data2,date,number,etc ....
    data1,data2,date,number,etc ....
    data1,data2,date,number,etc ....

      Thanks for that. I probably should have been more clear--I am indeed talking about a complex datastructure.

        JSON, XML, YAML, ...

        Storable needs the same version of Storable on all machines, and I think it also needs the same byte order on all machines.

        You could also use SQLite (via DBI / DBD::SQLite).

        Data::Dumper and string eval doesn't sound that good, it opens a hole that I would like to keep closed.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)