in reply to Tie Hash
check out this for example.... the first script creates the hash file, the second retreives it from file
and a retreive example#!/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);
#!/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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Tie Hash
by BioLion (Curate) on Nov 30, 2009 at 15:59 UTC |