Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2023-01-30 05:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?