in reply to Accessing keys through values

In case your values are unique in the hash, you can simply reverse it
%h = (a=>"A", "b"=>"B"); %h2 = reverse %h; print $h2{A}; #a
If not, you'll have to iterate over the hash.
%h = (a=>"A", "b"=>"B", "bb" => "B"); for ( keys %h ) { print $_ if $h{$_} eq "B"; }
oh ... and please use code-tags.


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: Accessing keys through values
by cybersmithuk (Initiate) on Apr 26, 2005 at 10:52 UTC
    As you have seen my script, the output I am getting is in the while loop and that too in the variable called $peak. Now, I should match which key contains the $peak value. For example, I have got the output from $peak as 41.876000 45.063000 48.922000 44.042000 46.863000 44.727000 45.491000 46.154000 I should search all the keys which hold these values and print both key and value like 78.3 =====> 41.876000. In this the 78.3 is the "key" and 41.876000 is the "value" (output from $peak in the while loop).