in reply to Sorting Complex Data Structure
my %by_id; push @{ $by_id{ $_->{id} } }, $_->{score} for @data; # Sort the scores for each id. $_ = [ sort { $b <=> $a } @$_ ] for values %by_id; # Sort the ids by the highest score. for my $id (sort { $by_id{$b}[0] <=> $by_id{$a}[0] } keys %by_id) { print "ID: $id\tScore: $_\n" for @{ $by_id{$id} }; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sorting Complex Data Structure
by Anonymous Monk on Jan 21, 2014 at 14:30 UTC |