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:

@courselist = sort { $a->[0] cmp $b->[0] or $a->[1] cmp $b->[1] } @courselist;
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.

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
    People vary on whether a hash style presentation would be visually clearer. For me it's far clearer to have just the data, lined up in columns. Having keys repeated on each line is, for me, visual clutter which I have to screen out, and it doesn't add information in a case like this where the type of each field is pretty much clear from the content.

    Conceptually, it's a good rule to have like things in arrays, and unlike things in hashes, and I think that rule gets fairly wide agreement. Perceptual styles are different. What may be helpful markers for tanktaus are visual noise that needs to be screened out for slower readers like me. One man's sushi is another man's bait.