How to save/restore a hash of hashes?

D

David Filmer

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!
 
A

Anno Siegel

David Filmer said:
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
 
D

David Filmer

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!
 
B

Ben Morrow

Quoth "David Filmer said:
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
 
E

Eric Bohlman

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Sorting hash of hashes 3
hash of hashes 9
A remark about 'field hashes' 2
Sorting hash of hashes 9
How to extract a value from all the hashes in a list of hashes? 3
Hash of Hashes 5
ordered hashes 13
Hash of hashes 5

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top