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
    Thank you! That worked great!
Re^2: Sorting in Perl
by sandeepb (Novice) on Oct 16, 2015 at 10:19 UTC
    there are many different ways in perl to sort numbers, i found those here
    use strict; use Data::Dumper; #Remove duplicates from array. my @array = qw/10 20 20 20 30 40 40 40 50 50 50/; print "\n Duplicate array: @array"; ##1) Good my %hash; $hash{$_} = 0 for (@array); # $hash{$_} = () for (@array); #You can do this also my @final = keys (%hash); print "\n Unique Array: @final"; print "\n"; ##2) Best of all my %hash = map { $_ , 1 } @array; my @uniq = keys %hash; print "\n Uniq Array:", Dumper(\@uniq);
    Source: Different ways to remove duplicates from array - sort and uniq in perl

      Those don't actually sort a list, they remove duplicate entries from it.

      Another variant on the same theme is using a slice, e.g.:

      my @array = (10 20 20 20 30 40 40 40 50 50 50); my %hash; @hash{ @array } = (); say keys %hash;

      But what I'd personally recommend is using the uniq function from List::MoreUtils (or List::AllUtils if you can't be bothered to remember whether functions are List:Util or List:MoreUtils).

      It avoids reinventing the wheel (fun as it is to do so as an academic exercise), it's shorter, and it makes it crystal clear what's going on, which will benefit whoever reads your code at a later time.

      EDIT: changed @hash{ @array } = 0 to @hash{ @array } = (); thanks for the suggestion to choroba.