Oct 22, 2003 #1 parkers Vendor Joined Oct 21, 2002 Messages 157 Location GB Hi, Is there anyway in perl to sort 2D arrays so that the integrity of all rows and elements remain intact? e.g. $array[0..m][0..n] | sort array by row 'm' Again any help or pointers appreciated. Thanks.
Hi, Is there anyway in perl to sort 2D arrays so that the integrity of all rows and elements remain intact? e.g. $array[0..m][0..n] | sort array by row 'm' Again any help or pointers appreciated. Thanks.
Oct 22, 2003 Thread starter #2 parkers Vendor Joined Oct 21, 2002 Messages 157 Location GB If anyone is interested? I've found a quite a tidy solution to a multidimensional array sort ... Alphabetical sort on 'element' '0': @sort = sort { $b->[0] cmp $a->[0]} @array; or in reverse order: @sort = reverse sort { $b->[0] cmp $a->[0]} @array; 'Sorted' array returned in @sort with array integrity intact. substitute <=> for cmp for a numerical sort on any array element. Upvote 0 Downvote
If anyone is interested? I've found a quite a tidy solution to a multidimensional array sort ... Alphabetical sort on 'element' '0': @sort = sort { $b->[0] cmp $a->[0]} @array; or in reverse order: @sort = reverse sort { $b->[0] cmp $a->[0]} @array; 'Sorted' array returned in @sort with array integrity intact. substitute <=> for cmp for a numerical sort on any array element.
Oct 22, 2003 #3 siberian Programmer Joined Sep 27, 2003 Messages 1,295 Location US AKA 'The Schwartzian Transform' A very handy beast for this sort of operation. I clicked in to suggest it and you'd already found it Upvote 0 Downvote
AKA 'The Schwartzian Transform' A very handy beast for this sort of operation. I clicked in to suggest it and you'd already found it