in reply to Re^2: Need help making my Merge Sort implementation stable
in thread Need help making my Merge Sort implementation stable

use Data::Dump 'pp'; # only used for output my @data = map { [ map { int rand(3) } 1 .. 5 ] } 1 .. 10; my @sorted = sort { $a->[1] <=> $b->[1] # sort by column 1 ascending || $a->[0] <=> $b->[0] # then column 0 || $b->[3] <=> $a->[3] # then column 3 descending } @data; pp @sorted;

gives

( [0, 0, 2, 2, 2], [0, 0, 0, 0, 1], [0, 0, 2, 0, 1], [1, 0, 2, 2, 0], [2, 0, 0, 2, 2], [0, 1, 0, 1, 2], [1, 1, 0, 2, 2], [1, 1, 1, 1, 2], [0, 2, 2, 0, 0], [2, 2, 2, 0, 0], )


Unless I state otherwise, all my code runs with strict and warnings

Replies are listed 'Best First'.
Re^4: Need help making my Merge Sort implementation stable
by taffer (Novice) on Jul 03, 2008 at 21:15 UTC
    Thank you, that did what I was needing to. Now I need to try to understand exactly what the BLOCK is telling it to do. I am just learning about array referencing and dereferencing s oI get a bit mixed up, still. I'll have to look at this some more to really grasp what is going on.