Your analysis of the problem is quite accurate. If you do those steps, one at a time, you get what you want. Keep in mind that hashes can't be sorted, just their keys and/or values.
I would like to sort Hash “A” (key) in descending order
my @sorted_scores = sort { $b <=> $a } keys %HashA;
and then align the (value) Hash “A” with Hash “B” (key).
my @sorted_words = map { $HashA{$_} } @sorted_scores;
Then use that sort, to align Hash “C” so that the key value pairs of "C" can be printed out in the same order as the sorted “A” Hash.
my @sorted_line_nums = map { $HashB{$_} } @sorted_words;
And the print:
print($HashC{$_}, "\n"); foreach @sorted_line_nums;
All together now:
print("$_\n"); foreach map { $HashC{$HashB{$HashA{$_}}} } sort { $b <=> $a } keys %HashA;
I'm curious as to how you handle two lines having the same score, if the score is the key.
In reply to Re: Sorting or Aligning Parallel Hashes
by ikegami
in thread Sorting or Aligning Parallel Hashes
by Gavin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |