Perl 6 Perl 6 today #35

Sorting a hash by value

Of course, any expression can be used as the sort criteria:

> my %h = <apple 4 cherry 7 banana -6>;  

> .say for %h.sort( { .value } );
banana  -6
apple   4
cherry  7

> .say for %h.sort( { .value.abs } );  # sort by absolute value
apple   4
banana  -6
cherry  7
Copyright © 2009
http://www.pmichaud.com/2009/pres/