note
moritz
<code>
my %nums = (
four => 4,
one => 1,
three => 3,
two => 2,
);
for %nums.pairs.sort: { $^a.value <=> $^b.value } -> $pair {
say $pair;
}
</code>
<p>(not necessarily shorter, but mentions <c>%nums</c> only once in the sort line).
<p>There was also a proposal to make the sort method accept a block of arity one that automatically performs a ST, but it doesn't seem to be [aes://S29|in the spec], and thusly isn't implemented by Rakudo right now.
<p>Update: [clinton] asked in the CB what the colon after the <c>sort</c> was about, so here's the explanation for everybody: The are two syntax forms for method calls in Perl 6, <c>$object.method($arg1, $arg2, ...)</c> and <c>$object.method: $arg1, $args, ...</c>. My example uses the latter to avoid more parenthesis.
729238
729238