in reply to Sorting in Perl
Really depends on what your data structure looks like. For instance, if you've got an array of arrays (i.e. array references), you could do the following:
my @sorted = sort { $b->[0] <=> $a->[0] || $b->[1] <=> $a->[1] || $b->[2] cmp $a->[2] } @list;
If you've got an array of strings of the form "100, 10, y", use a Schwartzian Transform (Wikipedia has more) to be able to use the above:
my @sorted = map { join ",", @$_ } sort { $b->[0] <=> $a->[0] || $b->[1] <=> $a->[1] || $b->[2] cmp $ +a->[2] } map { my @t = split /,/, $_; \@t } @list;
EDIT:
Update: Thank you all! Thank you AppleFritter, that worked like a charm!
You're welcome, partner! *tips hat*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re:Sorting in Perl
by perlUser345 (Acolyte) on Oct 15, 2015 at 16:04 UTC | |
|
Re^2: Sorting in Perl
by sandeepb (Novice) on Oct 16, 2015 at 10:19 UTC | |
by AppleFritter (Vicar) on Oct 16, 2015 at 10:47 UTC |