Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: getting hash key with value (List::Pairwise)

by lodin (Hermit)
on Apr 17, 2008 at 10:08 UTC ( #681103=note: print w/replies, xml ) Need Help??


in reply to getting hash key with value

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2022-01-27 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (70 votes). Check out past polls.

    Notices?