Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: ⭐ (arrays)
I want to be able to sort the "double-dimension" array by one of the colums...
eg. alphabeticaly by comparing items in column 2 of the array...
below some sample data:
The manual covers only case of hashes and uses subroutine for comparing items. But how to adopt that for comparing such an array? Thanx in advance... Joustin$foo[0][0] = "zenia"; $foo[0][1] = "markownikowa"; $foo[0][2] = +"10"; $foo[1][0] = "marek"; $foo[1][1] = "butalski"; $foo[1][2] = +"20"; $foo[2][0] = "teresa"; $foo[2][1] = "parufkowa"; $foo[2][2] = +"90"; $foo[3][0] = "bogumila"; $foo[3][1] = "pierdowa"; $foo[3][2] = +"40"; $foo[4][0] = "genowefa"; $foo[4][1] = "tempawa"; $foo[4][2] = +"50"; First -- let's sort these by the [][1] column... the result should be: marek brutalski 20 zenia markownikowa 10 teresa parufkowa 90 bogumila pierdawa 40 genowefa tempawa 50 sorting by the [][2] column should give us: zenia markownikowa 10 marek brutalski 20 bogumila pierdawa 40 genowefa tempawa 50 teresa parufkowa 90
Originally posted as a Categorized Question.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to sort array by columns maintaining the rows? (for C style arrays)⭐
by Russ (Deacon) on Jul 02, 2000 at 23:19 UTC | |
Re: How to sort array by columns maintaining the rows? (for C style arrays)⭐
by Anonymous Monk on Jul 02, 2000 at 19:41 UTC | |
by Anonymous Monk on Jul 03, 2000 at 18:20 UTC | |
Re: How to sort array by columns maintaining the rows? (for C style arrays)
by Anonymous Monk on Jul 14, 2000 at 18:47 UTC |
Back to
Seekers of Perl Wisdom