what comes to mind are chained comparisons in sort °
sort { $a->[0] cmp $b->[0] or $a->[1] cmp $b->[1] # * or $a->[2] cmp $b->[2] # * or ... # * } @AoA # *) only check if former was equal == 0 == false
if you don't know the number of fields, recursive comparisons come in handy.
I'm bu-la-zy, so constructing the recursion is left as exercise. ;-)
HTH!
In hindsight ... this particular case could also be solved in a loop.
So think about a more complicated data structures like trees to be sorted.
In the end it's about convenience ... every loop can be expressed as recursion and vice versa.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
°) see examples in code from line 39 onwards
In reply to Re^3: Recursive subroutines with sort
by LanX
in thread Recursive subroutines with sort
by holli
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |