in reply to sorting an array of an arrays
First comment is that I'd suggest an array of hashes over an array of arrays because I find it way easier to read a hash than an array when it's a list of disparate objects. Your outer array is really a list of courses - lists are what arrays are for. Your inner arrays are all a single course with a bunch of attributes - attributes are what hashes are good at. However, that probably doesn't change how to sort in your mind, so it's not going to solve your problem.
To sort on multiple fields, you just need to set up your sorting on those fields. It should be as simple as:
That way, if the 0's are identical (thus cmp return 0, or false), the or kicks in and we check the next one in the list.@courselist = sort { $a->[0] cmp $b->[0] or $a->[1] cmp $b->[1] } @courselist;
Hope that helps,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sorting an array of an arrays
by rodion (Chaplain) on Aug 13, 2006 at 11:30 UTC |