Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: help needed in retrieving the hash key

by inman (Curate)
on Apr 05, 2006 at 11:38 UTC ( #541351=note: print w/ replies, xml ) Need Help??


in reply to help needed in retrieving the hash key

An alternative method uses the each and keys functions to iterate over a hash and locate the keys. This has the advantage of coping with the more general case wher multiple instances of a value in addition to not requiring the storage of another hash.

my @keys = qw ( a b c d e f g h i j); my @vals = qw ( 1 1 1 4 5 6 7 8 9 0); my %hash; @hash{@keys} = @vals; my @ones = grep {(each %hash)[1] == 1} keys %hash; print "@ones\n";

Inverting the hash as shown previously is a better method if you are OK with the storage overhead and you will be doing multiple retrievals.


Comment on Re: help needed in retrieving the hash key
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2014-08-22 09:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (152 votes), past polls