G
g
Hi,
Given a key, I'm trying to access a specific array in a hash of
arrays. I'm not having much luck....
## Following the Perl docs, I populate the hash of arrays this way:
foreach $sonKey ( keys %son ) {
push @{ $sonRev{$sonKey} }, $son{$sonKey};
}
## This, based on the Perl docs, does work
## in accessing all the elements in the hash of arrays:
foreach $sonKey ( keys %sonRev ) {
print "theAnswer: ";
foreach $i ( 0 .. $#{ $sonRev{$sonKey} } ) {
print " $sonKey = $sonRev{$sonKey}[$i]";
}
print "\n";
}
## But the following doesn't work at all -- nothing is printed
$aKey = 13;
foreach $i ( 0 .. $#{ $sonRev{$aKey} } ) {
print "the sonKey for $aKey is $sonRev{$aKey}[$i]\n";
}
What am I doing wrong?
g
Given a key, I'm trying to access a specific array in a hash of
arrays. I'm not having much luck....
## Following the Perl docs, I populate the hash of arrays this way:
foreach $sonKey ( keys %son ) {
push @{ $sonRev{$sonKey} }, $son{$sonKey};
}
## This, based on the Perl docs, does work
## in accessing all the elements in the hash of arrays:
foreach $sonKey ( keys %sonRev ) {
print "theAnswer: ";
foreach $i ( 0 .. $#{ $sonRev{$sonKey} } ) {
print " $sonKey = $sonRev{$sonKey}[$i]";
}
print "\n";
}
## But the following doesn't work at all -- nothing is printed
$aKey = 13;
foreach $i ( 0 .. $#{ $sonRev{$aKey} } ) {
print "the sonKey for $aKey is $sonRev{$aKey}[$i]\n";
}
What am I doing wrong?
g