Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Counting Variations of Key in a Hash

by davidrw (Prior)
on Aug 09, 2005 at 15:29 UTC ( #482250=note: print w/replies, xml ) Need Help??

in reply to Counting Variations of Key in a Hash

So the end result for HIPPO1 and HIPPO2 should be the same, right? Assuming that, the following ends up with HIPPO as a key (no number -- just the 'root' name) (note that hashing on the 'root' animal name also eliminates the need for the nested looping over bigHash):
my %animals; while( my ($state, $zoos) = each %bighash ){ while( my ($zoo, $row) = each %$zoos ){ my $animal = $row->[1]; $animal =~ s/\d+$//; push @{$animals{$animal}->{$state}}, $zoo; } }
Note in your original code that @zoos probably shouldn't be globally scoped.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://482250]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2020-06-07 09:17 GMT
Find Nodes?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?

    Results (42 votes). Check out past polls.