Perl 6 Perl 6 today #32

Cool Perl 6: Hash sort by value

Perl 5:

# sort hash by value
for ( sort { $scores{$a} cmp $scores{$b} } keys(%scores) ) {
    print $_, "\t", $scores{$_}, "\n";
}

Perl 6:

.say for %scores.sort( { .value } )

Example:

> my %scores = < pmichaud 52   mäsak 95   PerlJam 78 >;
> .say for %scores.sort( { .value } );

pmichaud         52
PerlJam 78
mäsak   95
Copyright © 2009
http://www.pmichaud.com/2009/pres/