in reply to Store operation in a variable
Rather than burdening every comparison of the sort with a conditional test, it'll be more efficient to sort the keys to an array and then reverse the array conditionally:
my @sorted = sort { $scores{$b} <=> $scores{$a} } keys %scores; @sorted = reverse @sorted if condition; for ( @sorted ) { ... }
|
|---|