Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
How do you print the key(s) of the largest value in a hash? I have a script that counts the occurences of something and the occurences it the value of that key.
And I need it to determine the greatest value, sort by it and only print the highest keys/value. In this example the highest value is 4 shared by ORANGE and BLUE. I need it so it just prints these two hash elements.Key -> Value red -> 2 pink -> 1 orange -> 4 black -> 3 blue -> 4
Whether it's just one highest value or if X number share it, all the highest valued key/value pairs need to be sorted.
I am very confused at how to do this.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: printing largest hash value
by BrowserUk (Patriarch) on Feb 22, 2005 at 04:39 UTC | |
by bmann (Priest) on Feb 22, 2005 at 05:00 UTC | |
by BrowserUk (Patriarch) on Feb 22, 2005 at 05:03 UTC | |
Re: printing largest hash value
by thedoe (Monk) on Feb 22, 2005 at 03:42 UTC | |
Re: printing largest hash value
by brian_d_foy (Abbot) on Feb 22, 2005 at 04:06 UTC | |
Re: printing largest hash value
by sulfericacid (Deacon) on Feb 22, 2005 at 03:10 UTC | |
Re: printing largest hash value
by saskaqueer (Friar) on Feb 22, 2005 at 03:13 UTC | |
Re: printing largest hash value
by demerphq (Chancellor) on Feb 22, 2005 at 09:06 UTC | |
Re: printing largest hash value
by RiotTown (Scribe) on Feb 22, 2005 at 03:33 UTC | |
by tomhukins (Curate) on Feb 22, 2005 at 09:40 UTC |
Back to
Seekers of Perl Wisdom