Hi all, I can't seem to find the right syntax for
iterating over a 3 dimensional hash table. I realize
that the anonymous hashes are actually references but
I have not been successful at de-referencing them to get
at the keys and values. I can get it for a 2 dimensional
hash but not a 3 dimensional one.
Thanks in advance,
Paula
Here's the scriptlet: watch out for line wraps...
use strict;
#2 Dimensional Hash of hashes
my %tp2Lookup =(
'MNTHLY' => { #anonymous hash
'LIFEPLANS' => 'M_L_value',
'HEALTHPLANS'=> 'M_H_value'
},
'QTRLY' => { #anonymous hash
'LIFEPLANS' => 'Q_L_value',
'HEALTHPLANS'=> 'Q_H_value'
},
);
#3 Dimensional Hash of hashes
my %tp3Lookup =(
'QTRLY' => { #anonymous hash
'LIFEPLANS' => { #anonymous hash
'ABC' => 'Q_L_ABC_value',
'DEF' => 'Q_L_DEF_value',
'GHF' => 'Q_L_GHF_value',
},
'HEALTHPLANS'=> { #anonymous hash
'ABC' => 'Q_H_ABC_value',
'BCD' => 'Q_H_BCD_value',
'GHF' => 'Q_H_GHF_value',
},
},
'MNTHLY' => { #anonymous hash
'LIFEPLANS' => { #anonymous hash
'ABC' => 'M_L_ABC_value',
'DEF' => 'M_L_DEF_value',
'XYZ' => 'M_L_XYZ_value',
},
'HEALTHPLANS'=> { #anonymous hash
'ABC' => 'M_H_ABC_value',
'XYZ' => 'M_H_XYZ_value',
},
},
);
print "\nTest iterating over the 2 dimensional hash of hashes...\n";
foreach my $fileTypeKey (keys %tp2Lookup) {
print "$fileTypeKey => \n";
foreach my $tpKey (keys %{$tp2Lookup{$fileTypeKey}}) {
print "\t$tpKey => $tp2Lookup{$fileTypeKey}{$tpKey}\n";
}
}
print "\nTest iterating over the 3 dimensional hash of hashes...\n";
foreach my $fileTypeKey (keys %tp3Lookup) {
print "$fileTypeKey => \n";
foreach my $tpKey (keys %{$tp3Lookup{$fileTypeKey}}) {
print "\t$tpKey => $tp3Lookup{$fileTypeKey}{$tpKey}\n";
print "\tThis is a ",
ref($tp3Lookup{$fileTypeKey}{$tpKey})," reference. \n";
# how do i de-reference it and print the other anonymous hashes?
# all my attempts fail syntax checks
}
}
##end of scriptlet
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs