I'd like to sort it by $Institution and within that sort by $CourseNumber (and possibly other values)You just needed to break it down into pieces that perl can understand. "sort it by" you correctly translated as $$a[n] cmp $$b[n], but you left out the more difficult-to-translate "within that". It helps to ask yourself "what does this really mean, on a level that perl could understand?", the answer, in this case, being "if the institutions are different, sort by them, otherwise, sort by course number". Which leads pretty directly to the solution proposed to you. Extending it to handle the "and possibly other values" should indicate a loop to you, something like:
sort { my $compare; for (my $i = 0; !$compare && $i < @$a; ++$i) { $compare = $a->[$i] cmp $b->[$i]; } return $compare; }
In reply to Re^2: sorting an array of an arrays
by ysth
in thread sorting an array of an arrays
by Gnat53
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |