Dear Masters,
Given this hash I want to identify animal that:
1.Occur more than once within the states, AND
2.Occur in more than one states.
In this case the animal is HIPPO.
my %bighash = (
'Arizona'=> {
'ZOO_1' => [ '5','HIPPO', ['some arr'],['some arr']],
'ZOO_2' => [ '10','HIPPO',['some arr'],['some arr']],
'ZOO_3' => [ '2', 'PUMA', ['some arr'],['some arr']],
'ZOO_5' => [ '1', 'PUMA', ['some arr'],['some arr']],
},
'Indiana' => {
'ZOO_9' => [ '25', 'ZEBRA', ['some arr'],['some arr']],
'ZOO_5' => [ '13', 'MONKEY',['some arr'],['some arr']],
'ZOO_6' => [ '23', 'ZEBRA', ['some arr'],['some arr']],
},
'Nevada' => {
'ZOO_3' => [ '3', 'HIPPO', ['some arr'],['some arr']],
'ZOO_7' => [ '11', 'HIPPO',['some arr'],['some arr']],
'ZOO_4' => [ '21', 'LION', ['some arr'],['some arr']],
'ZOO_12' => [ '13', 'MONKEY',['some arr'],['some arr']],
},
);
Such that in the end it simply have:
Arizona
ZOO: ZOO_1 ANIMAL: HIPPO
ZOO: ZOO_2 ANIMAL: HIPPO
NEVADA
ZOO: ZOO_3 ANIMAL: HIPPO
ZOO: ZOO_7 ANIMAL: HIPPO
What's wrong with my code below such that it doesn't gives
the answers correctly?
print Dumper \%bighash ;
foreach my $states ( sort keys %bighash )
{
print "$states\n";
foreach my $zoo ( keys %{$bighash{$states}} )
{
my $cur = $bighash{$states}{$zoo}->[1];
my $count = 0;
foreach my $nzoo ( keys %{$bighash{$states}} )
{
my $nxt = $bighash{$states}{$nzoo}->[1];
if ( $cur eq $nxt )
{
$count++;
if ( $count > 1 )
{
print "ZOO: $zoo ANIMAL: $nxt\n";
}
}
} # ----- end foreach -----
} # ----- end foreach -----
} # ----- end foreach -----
---
neversaint and everlastingly indebted.......