Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2021-10-19 21:34 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (77 votes). Check out past polls.