in reply to two order sort
Multi-key sort, both in descending order:
>perl -wMstrict -le "use List::Util qw(sum); ;; my $scan = { a => [ 5, 6 ], b => [ 5, 10, 15 ], c => [ 100 ], d => [ 8, 9 ] }; ;; my @sorted = map $_->[0], sort { $b->[1] <=> $a->[1] or $b->[2] <=> $a->[2] } map [ $_, scalar @{ $scan->{$_} }, sum @{ $scan->{$_} } ], keys %$scan ; ;; print qq{@sorted}; " b d a c
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: two order sort
by LanX (Saint) on Mar 05, 2013 at 01:30 UTC | |
by AnomalousMonk (Archbishop) on Mar 05, 2013 at 02:25 UTC | |
by BrowserUk (Patriarch) on Mar 05, 2013 at 03:49 UTC | |
by AnomalousMonk (Archbishop) on Mar 05, 2013 at 07:04 UTC | |
by BrowserUk (Patriarch) on Mar 05, 2013 at 15:11 UTC | |
by LanX (Saint) on Mar 05, 2013 at 09:41 UTC | |
by AnomalousMonk (Archbishop) on Mar 05, 2013 at 22:01 UTC | |
by ag4ve (Monk) on Mar 07, 2013 at 16:11 UTC |
In Section
Seekers of Perl Wisdom