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
Answer: How to sort array by columns maintaining the rows? (for C style arrays) contributed by QandAEditors Since these seem to be names, let me add a quick note about sorting on two (or more) columns. The comparison operators return 0 when the operands are equal. So, using the || operator, we can sort first by Last Name, then First Name, then Score. In the second example above, @FullSort looks like: because it is sorted by Last Name, then First Name, then Score. Russ |
Answer: How to sort array by columns maintaining the rows? (for C style arrays) contributed by QandAEditors the following code shows how to sort this data structure by any of its three columns. notice that the sorts on columns 0 and 1, the names, are performed ASCIIbetically, while the sort by number is done numerically. |
Please (register and) log in if you wish to add an answer
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |