Your description of what you wanted was pretty good:
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;
}
| [reply] [d/l] [select] |
My apologies then, and enjoy the excellent answers from Tanktalus et al. Good on you for building your own site - I hope you are able to get to where you want to be with the help of Perlmonks!
PS: I haven't been to MA for about 6 years, but I miss visiting Boston and the rest of New England - next time I come I'll try and pop in to your shop :) | [reply] |