This is trivial using List::Pairwise, even if the values aren't unique.

use List::Pairwise 'mapp'; my %hash = ( foo => 1, bar => 2, baz => 1, bux => 0, ); my $val = $hash{foo}; my @keys = mapp { $b eq $val ? $a : () } %hash; print "@keys"; __END__ baz foo
Even if you think that your values are unique it's sometimes a good idea to assert this:
my ($key, @too_many) = mapp { $b eq $val ? $a : () } %hash; ! @too_many or die 'Too many ...';

lodin


In reply to Re: getting hash key with value (List::Pairwise) by lodin
in thread getting hash key with value by sovixi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":