ag4ve has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to sort a hashref of arrays first by the number of elements in the array and then the total count in all elements:
snip
Should print b, d, a, c but idk what it's currently doing.
snip
use List::Util qw(reduce); my $scan = {a => [ 5, 6 ], b => [ 5, 10, 15 ], c = [ 100 ], d => [ 8, +9 ] }; foreach my $sip (sort { $scan->{$b} <=> $scan->{$a} or +(reduce { $b + $a } @{$scan->{$b}}) <=> +(reduce +{$b + $a } @{$scan->{$a}}) } (keys %$scan))
Should print b, d, a, c but idk what it's currently doing.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: two order sort
by choroba (Cardinal) on Mar 05, 2013 at 00:17 UTC | |
Re: two order sort
by AnomalousMonk (Archbishop) on Mar 05, 2013 at 01:05 UTC | |
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 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 | |
Re: two order sort
by LanX (Saint) on Mar 05, 2013 at 00:32 UTC | |
Re: two order sort
by salva (Canon) on Mar 05, 2013 at 11:39 UTC |
Back to
Seekers of Perl Wisdom