Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
print "Content-type: text/html\n\n"; while(<DATA>) { chomp; @sorted=(); @sorted = split(/\|/); $sorted{$sorted[0]} = [@sorted]; } print "$_->[0]|$_->[1]|$_->[2]<BR>\n" for sort {$b->[0] cmp $a->[0]} v +alues %sorted; __DATA__ 24|index.htm|http://localhost/~owner/index.htm 18|alertBoxes.htm|http://localhost/~owner/alertboxes.htm 4|andrewsGame.htm|http://localhost/~owner/andrewsgame.htm 3|bounceGame.htm|http://localhost/~owner/bouncegame.htm 21|browserRace.htm|http://localhost/~owner/browserrace.htm 6|breakFrames.htm|http://localhost/~owner/breakframes.htm 44|colorTables.htm|http://localhost/~owner/colortables.htm 61|humanReadable.htm|http://localhost/~owner/humanreadable.htm 27|mouseXY.htm|http://localhost/~owner/mousexy.htm 9|calculator.htm|http://localhost/~owner/calculator.htm 15|fakeFormat.htm|http://localhost/~owner/fakeformat.htm 2|makeCircle.htm|http://localhost/~owner/makecircle.htm 22|imageSwap.htm|http://localhost/~owner/imageswap.htm 5|easyDate.htm|http://localhost/~owner/easydate.htm 66|encoder.htm|http://localhost/~owner/encoder.htm 57|bgChanger.htm|http://localhost/~owner/bgchanger.htm 10|centipede.htm|http://localhost/~owner/centipede.htm 11|cookies.htm|http://localhost/~owner/cookies.htm
The output of this script is:
9|calculator.htm|http://localhost/~owner/calculator.htm 66|encoder.htm|http://localhost/~owner/encoder.htm 61|humanReadable.htm|http://localhost/~owner/humanreadable.htm 6|breakFrames.htm|http://localhost/~owner/breakframes.htm 57|bgChanger.htm|http://localhost/~owner/bgchanger.htm 5|easyDate.htm|http://localhost/~owner/easydate.htm 44|colorTables.htm|http://localhost/~owner/colortables.htm 4|andrewsGame.htm|http://localhost/~owner/andrewsgame.htm 3|bounceGame.htm|http://localhost/~owner/bouncegame.htm 27|mouseXY.htm|http://localhost/~owner/mousexy.htm 24|index.htm|http://localhost/~owner/index.htm 22|imageSwap.htm|http://localhost/~owner/imageswap.htm 21|browserRace.htm|http://localhost/~owner/browserrace.htm 2|makeCircle.htm|http://localhost/~owner/makecircle.htm 18|alertBoxes.htm|http://localhost/~owner/alertboxes.htm 15|fakeFormat.htm|http://localhost/~owner/fakeformat.htm 11|cookies.htm|http://localhost/~owner/cookies.htm 10|centipede.htm|http://localhost/~owner/centipede.htm ||
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with sorting numbers.
by eibwen (Friar) on Apr 26, 2005 at 02:58 UTC | |
|
Re: Problem with sorting numbers.
by ikegami (Patriarch) on Apr 26, 2005 at 03:00 UTC | |
|
Re: Problem with sorting numbers.
by polettix (Vicar) on Apr 26, 2005 at 12:57 UTC | |
|
Re: Problem with sorting numbers.
by Anonymous Monk on Apr 26, 2005 at 03:06 UTC |