Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: sorting array of array references with multiple dereferenced array elementsby jonadab (Parson) |
on Sep 23, 2014 at 12:51 UTC ( [id://1101632]=note: print w/replies, xml ) | Need Help?? |
If we knew in advance how many elements each of your sub-arrays were going to have, and if it were a fairly small number, we could do this with an inlined sort routine, perhaps something along these lines (assuming three elements in each sub-array):
Note: This code is untested. This is pretty basic, and works when we don't mind listing each of the sort criteria. However, if we don't know how many elements there are, or if there are a whole bunch, it may be more practical to have the sort routine loop over the subarray indices from 0 to whatever, returning as soon as it has an answer. (The return values should match what <=> would return; see perlop for further information about that.)
Note: This code is untested. Note too that the way you define the AoA feels kind of awkward, like maybe you aren't really comfortable with Perl data structures yet. That's fine, at first, but you will want to work toward being more comfortable with Perl data structures until you are able to do things like this:
In Section
Seekers of Perl Wisdom
|
|