Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Getting Keys of Hash from Values

by ptum (Priest)
on Nov 16, 2005 at 21:13 UTC ( #509196=note: print w/replies, xml ) Need Help??


in reply to Getting Keys of Hash from Values

Or how 'bout this?
#!/usr/local/bin/perl -w use strict; my %hash = ( apple => 'red', banana => 'yellow', orange => 'orange', lemon => 'yellow', ); my $value = 'yellow'; my %newhash = reverse %hash; print $newhash{$value}, "\n";

Replies are listed 'Best First'.
Re^2: Getting Keys of Hash from Values
by ikegami (Patriarch) on Nov 16, 2005 at 21:14 UTC

    That doesn't return all the keys if the values are not unique. According to the output either lemons or bananas aren't yellow.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2022-05-21 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (76 votes). Check out past polls.

    Notices?