Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Getting Keys of Hash from Values

by duff (Parson)
on Nov 16, 2005 at 21:10 UTC ( #509195=note: print w/replies, xml ) Need Help??


in reply to Getting Keys of Hash from Values

I think you want something like this:

my @keys = grep { $hash{$_} eq $value } keys %hash;
That iterates over all of the keys of %hash and if any value in the hash is equal to the value we're interested in, then the expression evaluates to a true value and so the key gets put into the @keys array.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2022-05-28 13:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (99 votes). Check out past polls.

    Notices?