Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: How to get Keys from hash having same value?

by NetWallah (Canon)
on Jan 07, 2008 at 07:08 UTC ( #660769=note: print w/replies, xml ) Need Help??


in reply to How to get Keys from hash having same value?

If you are going to be making this query frequently, you may want to pre-build a "reverse lookup" hash:
my %h1 = qw (1 a 2 b 3 a 4 c); my %h2; #Used for Value-to-key lookup push @{$h2{$h1{$_}}},$_ for keys %h1; # Builds the reverse hash print join( ",",@{$h2{a}}); # Lookup and print all keys in h1 that +contain the value 'a' # Prints: 1,3

     "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2020-08-05 17:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (36 votes). Check out past polls.

    Notices?