Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Getting Keys of Hash from Values

by ptum (Priest)
on Nov 16, 2005 at 21:13 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-29 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found