coldfingertips has asked for the wisdom of the Perl Monks concerning the following question:
I have a hash I need sorted..TWICE. I asked this in the chat box but that got confusing, so here's the problem.
I need to sort a hash by values (the values are all whole numbers) but in some cases, many of the hash keys have the same value. How can I then sort these alphabetically?
Unsorted
Using foreach (sort {$saved_key{$b} cmp $saved_key{$a}} keys %saved_key)rock => 3 candle => 25 bug => 3 rain => 12 dust => 17 spider => 12
Desired:candle => 25 dust => 17 spider => 12 rain => 12 rock => 3 bug => 3
If two or more values are the same, I want to sort them alphanumerically. Any help would be much appreciated.candle => 25 dust => 17 rain => 12 spider => 12 bug => 3 rock => 3
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Twice the pleasure of sorting a hash
by broquaint (Abbot) on Apr 26, 2004 at 09:52 UTC | |
by coldfingertips (Pilgrim) on Apr 26, 2004 at 09:55 UTC | |
Re: Twice the pleasure of sorting a hash
by Limbic~Region (Chancellor) on Apr 26, 2004 at 12:14 UTC | |
Re: Twice the pleasure of sorting a hash
by ph0enix (Friar) on Apr 26, 2004 at 09:57 UTC | |
by halley (Prior) on Apr 26, 2004 at 13:52 UTC | |
Re: Twice the pleasure of sorting a hash
by Anonymous Monk on Apr 26, 2004 at 19:00 UTC | |
Re: Twice the pleasure of sorting a hash
by Anonymous Monk on Apr 26, 2004 at 20:19 UTC |
Back to
Seekers of Perl Wisdom