In Perl, I can do:
my @unit_indices = sort {
$units{$b}[0] <=> $units{$a}[0]
or
$a cmp $b
} keys %units;
which sorts by one field (array element) descending and the other (hash key) ascending, but causes perlcritic to complain:
Forbid $b before $a in sort blocks at line X, column Y. See page 152 of PBP. (Severity: 1)
Perl Best Practices recommends using reverse instead.
But the operation would be much more comprehensible if you wrote:
@sorted_results = reverse sort @unsorted_results;
However, I haven’t found a way to have subsorts that run in opposite directions.
Obviously, I can tell perlcritic to ignore this, but I’d like to know how to accomplish what I need and make perlcritic happy.
I agree with tchrist’s comment, but taking your question at face value:
1) use
## no critic2) Use a
.perlcriticrcfile3) Change the sense of your comparison