http://qs1969.pair.com?node_id=509196


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.