How to save/restore a hash of hashes?

Discussion in 'Perl Misc' started by David Filmer, Nov 9, 2004.

  1. David Filmer

    David Filmer Guest

    I want to be able to save the values of a hash of hashes (of hashes of
    hashes, actually) to a textfile and be able to restore the hash (at a later
    time) by reading the textfile.

    If it were a simple hash, it would be trivial to save/reload the key/value
    pairs. But a hash of hashes (of hashes of hashes) doesn't lend itself to
    such a trivial solution. I could do a "brute force" approach, drilling down
    to each value and saving it in an expected order (and restore it in a
    brute-force approach in the same order) but that doesn't seem very elegant
    (in fact, it's downright ghastly).

    I would appreciate a suggestion as to how I might accomplish this in an
    elegant fashion.

    Thanks!
     
    David Filmer, Nov 9, 2004
    #1
    1. Advertising

  2. David Filmer

    Anno Siegel Guest

    David Filmer <> wrote in comp.lang.perl.misc:
    > I want to be able to save the values of a hash of hashes (of hashes of
    > hashes, actually) to a textfile and be able to restore the hash (at a later
    > time) by reading the textfile.


    Data::Dumper or Storable (standard modules). FreezeThaw from CPAN.

    Anno
     
    Anno Siegel, Nov 9, 2004
    #2
    1. Advertising

  3. David Filmer

    David Filmer Guest

    Awesome - thanks! A quick read-thru of Data::Dumper looks great but Storable
    (and prehaps FreezeThaw - still figuring that one out) is incredible and
    exactly what I need. I very much appreciate you pointing me in this
    direction.

    Cheers!

    "Anno Siegel" <-berlin.de> wrote in message
    news:cmq3sh$sf3$-Berlin.DE...
    > Data::Dumper or Storable (standard modules). FreezeThaw from CPAN.
    >
    > Anno
     
    David Filmer, Nov 9, 2004
    #3
  4. David Filmer

    Ben Morrow Guest

    Quoth "David Filmer" <>:
    > "Anno Siegel" <-berlin.de> wrote in message
    > news:cmq3sh$sf3$-Berlin.DE...
    > > Data::Dumper or Storable (standard modules). FreezeThaw from CPAN.

    >
    > Awesome - thanks! A quick read-thru of Data::Dumper looks great but Storable
    > (and prehaps FreezeThaw - still figuring that one out) is incredible and
    > exactly what I need. I very much appreciate you pointing me in this
    > direction.


    The only disadvantage of Storable is that it produces binary, rather
    than text, files. You did originally specify text, but may not have
    meant it.

    If you decide you *do* need text files, I would recommend Data::Dump
    from CPAN rather than D:Dumper, as I find it easier to use.

    Ben

    --
    Joy and Woe are woven fine,
    A Clothing for the Soul divine William Blake
    Under every grief and pine 'Auguries of Innocence'
    Runs a joy with silken twine.
     
    Ben Morrow, Nov 9, 2004
    #4
  5. David Filmer

    Eric Bohlman Guest

    Ben Morrow <> wrote in
    news::

    >
    > Quoth "David Filmer" <>:
    >> "Anno Siegel" <-berlin.de> wrote in message
    >> news:cmq3sh$sf3$-Berlin.DE...
    >> > Data::Dumper or Storable (standard modules). FreezeThaw from CPAN.

    >>
    >> Awesome - thanks! A quick read-thru of Data::Dumper looks great but
    >> Storable (and prehaps FreezeThaw - still figuring that one out) is
    >> incredible and exactly what I need. I very much appreciate you
    >> pointing me in this direction.

    >
    > The only disadvantage of Storable is that it produces binary, rather
    > than text, files. You did originally specify text, but may not have
    > meant it.
    >
    > If you decide you *do* need text files, I would recommend Data::Dump
    > from CPAN rather than D:Dumper, as I find it easier to use.


    And take at least a glance at YAML.
     
    Eric Bohlman, Nov 11, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rp
    Replies:
    1
    Views:
    557
    red floyd
    Nov 10, 2011
  2. Scott  Gilpin
    Replies:
    2
    Views:
    231
  3. Perl Learner

    Hashes of hashes or just one hash ?

    Perl Learner, Jun 8, 2005, in forum: Perl Misc
    Replies:
    11
    Views:
    223
  4. Tim O'Donovan

    Hash of hashes, of hashes, of arrays of hashes

    Tim O'Donovan, Oct 27, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    223
  5. Replies:
    3
    Views:
    216
Loading...

Share This Page