.... 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 processingcheck 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);
|