in reply to How would I sort a two-dimensional array by multiple columns?

It would look something like this:

my @a = ([1,2], [3,4]); my @b = sort { $a->[0] <=> $b->[0] || # the result is -1,0,1 ... $a->[1] <=> $b->[1] # so [1] when [0] is same } @a;

Check out sort for the full story. And, you'd probably have to maintain some kind of global setting for the sub (indicating which columns to sort by) or call the sub from the sort block indicating it there. Although, calling functions from the sort block can get surprisingly slow. The worst case is O(n*log(n)) I believe and calling functions in perl is among the slowest thing it does.

I'm sure you'll figure it out.

UPDATE: NetWallah, sorry, no bugs here. This was not intended to be a complete solution. What's the fun in having someone else write it all out for you?

-Paul

Replies are listed 'Best First'.
Re^2: How would I sort a two-dimensional array by multiple columns?
by dbmathis (Scribe) on Mar 15, 2008 at 20:15 UTC

    Worked like a CHARM! Thanks! That was also MUCH easier than I would have ever imagined. Best Regards

    After all this is over, all that will really have mattered is how we treated each other.