Sorting a hash by value
Perl 5:
# sort hash by value for ( sort { $h{$a} cmp $h{$b} } keys(%h) ) { print $_, "\t", $h{$_}, "\n"; }
Perl 6:
.say for %h.sort( { .value } )
Example:
> my %h = <apple 4 cherry 7 banana -6>; > .say for %h.sort( { .value } ); banana -6 apple 4 cherry 7