in reply to Can I tie a hash of hashes to a file?

I think the module Storable can be of help, It has the methods 'store' and 'retrieve' which are direct to work with when storing datastructures to files and returning them back,in addition to other utilities, check the link above...In my Windoze Machine, the DB_File module did not really work for me, so I used this one instead...
use strict; use warnings; use Storable; my %hash; $hash{"Janet Jones"} = { "spouse" => "Bob Jones", "son 1" => "Tom Jones", "son 2" => "Pete Jones", "pet 1" => "Boyle", "father" => "Richard Smith", "mother" => "Fran Smith", "sister 1" => "Louise Williams", "address" => "1 Main St, Littleton, PA, 55555", }; $hash{"Bob Jones"} = { "spouse" => "Janet Jones", "son 1" => "Tom Jones", "son 2" => "Pete Jones", "pet 1" => "Boyle", "father" => "Paul Jones", "mother" => "Stella Jones", "brother 1" => "Paul Jones, Jr", "brother 2" => "Vince Jones", "brother 3" => "Dan Jones", "sister 1" => "Andrea Limux", "address" => "1 Main St, Littleton, PA, 55555", }; store(\%hash, "HashOfHashesFile.txt"); my %friends = %{retrieve("HashOfHashesFile.txt") }; for my $name (keys %friends){ print "$name->\n"; for my $info(keys %{$friends{$name}}){ print " " x length("$name"); print "$info-> $friends{$name}{$info}\n"; } }
OUTPUT:
Janet Jones-> spouse-> Bob Jones son 1-> Tom Jones pet 1-> Boyle mother-> Fran Smith father-> Richard Smith address-> 1 Main St, Littleton, PA, 55555 son 2-> Pete Jones sister 1-> Louise Williams Bob Jones-> spouse-> Janet Jones son 1-> Tom Jones brother 3-> Dan Jones pet 1-> Boyle mother-> Stella Jones brother 2-> Vince Jones father-> Paul Jones brother 1-> Paul Jones, Jr address-> 1 Main St, Littleton, PA, 55555 sister 1-> Andrea Limux son 2-> Pete Jones
This link to a Wikipedia article is very informative of the concept of data serialization..


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

Replies are listed 'Best First'.
Re^2: Can I tie a hash of hashes to a file?
by r1n0 (Beadle) on Nov 12, 2009 at 18:58 UTC
    Thank you very much for the responses. I have a question about the module Storable, though. Storable just unloads content to a file, while keeping information in memory, true? What if one wanted to use a file to use the file for the hash of hashes rather than using memory? The method you outlined is one method for handling persistency. I will be examining DBM::Deep. Thanks.

    Thanks.