I take it you want to sort first by the key which contains the highest score, and then within each key by that key's score. Here's one way to do it:
Update: removed unnecessary intermediate array
my @sorted;
for my $key (keys %entry) {
my $scores = $entry{$key}{'Score'};
my $locations = $entry{$key}{'Location'};
my @array = map { [ $key, $scores->[$_],$locations->[$_] ] } 0 ..
+$#$scores;
@array = sort { $b->[1] <=> $a->[1] } @array;
push(@sorted, [ $array[0][1], \@array ]);
}
@sorted = sort { $b->[0] <=> $a->[0] } @sorted;
for my $array (@sorted) {
my $aoa = $array->[1];
for my $result (@$aoa) {
print "$result->[0] $result->[1] $result->[2]\n";
}
}
Output:
TRA 23 4-19
TRA 15 7-15
TRA 2 78-120
BLA 10 2-10
BLA 5 1-10
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.