in reply to max "value " of an hash

Code up something like this Edit: Misread the question
print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Replies are listed 'Best First'.
Re^2: max "value " of an hash
by k_manimuthu (Monk) on Dec 21, 2010 at 09:20 UTC
    # get values with numerical sort @values = sort {$a<=>$b} values %hash; # get the array last value, that considered the max value of the hash $max=$values[$#values]; print $max;
      You can find only one key from hash...
      Some time you can have situatuin like this:

      max value = 5
      but in hash present
      ${'asdf'}=5;
      ${'asdfg'}=5;

      This algorithm can show only last key or value...

        Hi Khariton,

        Yes you are right, for my previous node I just show how to get the maximum value in a hash. Now, I had updated the code, that will get the maximum value, as well as the corresponding keys.

        # get values with numerical sort @values = sort {$a<=>$b} values %hash; # process each element foreach (keys %hash) { # get the key name of the maximum value print "\nkey : $_ : value $hash{$_}" if ($values[$#values] == $has +h{$_}); }