| gundalav@gmail.com 2005-08-04, 10:00 pm |
| Hi,
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.
Finally sorts that selected animal according to its number.
Such that it finally prints "the single best":
HIPPO, 11
features1
features2
That values is taken from Nevada State, Zoo_7.
The other consideration is if the animal
occur only one time in one state. E.g. HIPPO in Indiana Zoo_4
It is just ignored.
How can I improve my code below such that
it get the result I want? I'm really stuck.
Hope to hear from you guys again.
Thanks,
GundalaV
__BEGIN__
my %bighash = (
#Yes, features is in AoA
'Arizona'=> {
'ZOO_1' => [ '5','HIPPO', ['features1'],['features2']],
'ZOO_2' => [ '10','HIPPO',['features1'],['features2']
],
'ZOO_3' => [ '2', 'PUMA', ['features1'],['features2']],
'ZOO_5' => [ '1', 'PUMA', ['features1'],['features2']],
},
'Indiana' => {
'ZOO_4' => [ '2','HIPPO',['features1'],['features2']]
,
'ZOO_9' => [ '25', 'ZEBRA', ['features1'],['features2']],
'ZOO_5' => [ '13', 'MONKEY',['features1'],['features2']],
'ZOO_6' => [ '23', 'ZEBRA', ['features1'],['features2']],
},
'Nevada' => {
'ZOO_3' => [ '3', 'HIPPO', ['feature1'],['feature2']],
'ZOO_7' => [ '11', 'HIPPO',['feature1'],['feature2']],
'ZOO_4' => [ '21', 'LION', ['feature1'],['feature2']],
'ZOO_12' => [ '13', 'MONKEY',['some arr'],['some arr']],
},
);
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 )
{
# How can I proceed from here?
#print "ZOO: $zoo ANIMAL: $nxt\n";
}
}
} # ----- end foreach -----
} # ----- end foreach -----
} # ----- end foreach -----
|