http://qs321.pair.com?node_id=660769


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