programming-examples/perl/Hash/Numerically Sort a Hash by Values in Descending Order.pl
2019-11-15 12:59:38 +01:00

15 lines
328 B
Raku

sub desc_sort_salary {
$salary{$b} <=> $salary{$a}; # Reverse $a and $b
}
%salary = (
"P" => 10,
"S" => 12,
"C" => 5,
"S" => 6,
"L" => 11,
"D" => 8,
);
foreach $key (sort desc_sort_salary(keys(%salary))) {
printf "\t% -20s%5d\n", $key, $salary{$key};
}