Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: highest value in hash

by LanX (Canon)
on Mar 31, 2013 at 03:35 UTC ( #1026322=note: print w/ replies, xml ) Need Help??


in reply to highest value in hash

a maximal value can belong to more than just one key!

DB<140> %h = map {$_ => int rand 3} "a" .."f" => ("a", 1, "b", 0, "c", 2, "d", 2, "e", 2, "f", 0) DB<141> use List::Util qw/max/ DB<142> $max = max values %h => 2 DB<143> @max_keys = grep { $h{$_} == $max } keys %h => ("e", "d", "c")

Cheers Rolf

( addicted to the Perl Programming Language)


Comment on Re: highest value in hash
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-08-21 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (128 votes), past polls