Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: highest value in hash

by LanX (Chancellor)
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)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1026322]
help
Chatterbox?
[LanX]: But reu germans have no humor, better to refrain from this site till the troll is gone...
[LanX]: true
[shmem]: I disagree
[LanX]: sure you are German
[shmem]: germans do have humour. Open debate is what germans, and what humour. There. :-)
[LanX]: :-P

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2017-04-27 19:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (513 votes). Check out past polls.