Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: highest value in hash

by LanX (Saint)
on Mar 31, 2013 at 03:35 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1026322]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-20 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found