Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: max "value " of an hash

by k_manimuthu (Monk)
on Dec 21, 2010 at 09:20 UTC ( #878198=note: print w/ replies, xml ) Need Help??


in reply to Re: max "value " of an hash
in thread max "value " of an hash

# 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;


Comment on Re^2: max "value " of an hash
Download Code
Re^3: max "value " of an hash
by Khariton (Sexton) on Dec 21, 2010 at 10:44 UTC
    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{$_}); }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2014-04-19 13:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (480 votes), past polls