in reply to Tie Hash

.... there is also Storable.... ..... you might want to consider thread safety in whatever module you select......just in case you decide to use threads to speed up processing

check out this for example.... the first script creates the hash file, the second retreives it from file

#!/usr/bin/perl # the storer use strict; use warnings; use Data::Dumper; use Storable; my (%kids_of_wife, $man, $wife); $kids_of_wife{"Jacob"} = { "Leah" => ["Reuben", "Simeon", "Levi", "Judah", "Issachar", "Zebulun +"], "Rachel" => ["Joseph", "Benjamin"], "Bilhah" => ["Dan", "Naphtali"], "Zilpah" => ["Gad", "Asher"], }; $kids_of_wife{"Bill"} = { "Betty" => ["Bob", "Willy", "Fred", "Bilbo", "Frodo", "Dimwitia"], "Joan" => ["Mike", "Ben"], "Harriet" => ["Danny", "Hondo"], "Mary" => ["Marion", "Egad", "Clancy"], }; store(\%kids_of_wife,"zzwifehash"); print '################################################',"\n"; foreach (keys %kids_of_wife) { print $_,"\n"; } print '################################################',"\n"; foreach (keys %kids_of_wife) { print foreach (keys %{$kids_of_wife{$_}}),"\n"; } print '################################################',"\n"; foreach (keys %kids_of_wife) { my $man = $_; foreach (keys %{$kids_of_wife{$man}}){; print $_,"\n"; my $wife = $_; print @{$kids_of_wife{$man}{$wife}},"\n"; }} print '################################################',"\n"; foreach (keys %kids_of_wife) { $man = $_; foreach (keys %{$kids_of_wife{$man}}){; $wife = $_; print "$man + $wife = "; print "@{$kids_of_wife{$man}{$wife}}\n"; }} print '################################################',"\n"; #print Dumper(%kids_of_wife);
and a retreive example
#!/usr/bin/perl # the retreiver use strict; use warnings; use Data::Dumper; use Storable; my (%kids_of_wife,$man,$wife); #$href = retrieve("zzwifehash"); # by ref %kids_of_wife = %{retrieve('zzwifehash')}; # direct to hash print '################################################',"\n"; foreach (keys %kids_of_wife) { print $_,"\n"; } print '################################################',"\n"; foreach (keys %kids_of_wife) { print foreach (keys %{$kids_of_wife{$_}}),"\n"; } print '################################################',"\n"; foreach (keys %kids_of_wife) { my $man = $_; foreach (keys %{$kids_of_wife{$man}}){; print $_,"\n"; my $wife = $_; print @{$kids_of_wife{$man}{$wife}},"\n"; }} print '################################################',"\n"; foreach (keys %kids_of_wife) { $man = $_; foreach (keys %{$kids_of_wife{$man}}){; $wife = $_; print "$man + $wife = "; print "@{$kids_of_wife{$man}{$wife}}\n"; }} print '################################################',"\n"; #print Dumper(%kids_of_wife);

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku

Replies are listed 'Best First'.
Re^2: Tie Hash
by BioLion (Curate) on Nov 30, 2009 at 15:59 UTC

    Thanks - You make a good point - again DBM::Deep seems to do well, all I need to do is specify

    my $db = DBM::Deep->new( file => "foo.db", locking => 1 );
    and the locking is taken care of for me (including shared for reading).

    Just a something something...