Perl 6 Cool Perl 6 #57

Cool Perl 6: Hash sort by value

If the comparison block for sort takes only one parameter, it returns the value to be compared

%scores.sort( { $^a.key }   );     # sort hash by keys

%scores.sort( { $^a.value } );     # sort hash by value

@list.sort( { $^a.name } );   # sort @list by .name of each element

A block with no explicit parameters has $_ as an implicit parameter

%scores.sort( { $_.value } );      # sort hash by value

%scores.sort( { .value } );        # use implicit $_
Copyright © 2010
http://www.pmichaud.com/2010/pres/