Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: highest value in hash

by hdb (Monsignor)
on Apr 01, 2013 at 08:55 UTC ( #1026444=note: print w/replies, xml ) Need Help??


in reply to highest value in hash

Should performance be not your highest goal, you can sort the keys of the hash by their values in descending order and pick the first one:

use warnings; use strict; my %hash= ( '1', '8', '2', '6', '3','3' ,'4','7'); my @keys = sort { $hash{$b} <=> $hash{$a} } keys %hash; print "Key with highest value is $keys[0].\n";

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2022-08-10 10:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?