Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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)

Comment on Re: highest value in hash
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2015-11-30 09:28 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (769 votes), past polls