Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: [Perl6] Sort a hash by value

by moritz (Cardinal)
on Dec 09, 2008 at 19:13 UTC ( #729240=note: print w/ replies, xml ) Need Help??


in reply to [Perl6] Sort a hash by value

my %nums = ( four => 4, one => 1, three => 3, two => 2, ); for %nums.pairs.sort: { $^a.value <=> $^b.value } -> $pair { say $pair; }

(not necessarily shorter, but mentions %nums only once in the sort line).

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 in the spec, and thusly isn't implemented by Rakudo right now.

Update: clinton asked in the CB what the colon after the sort was about, so here's the explanation for everybody: The are two syntax forms for method calls in Perl 6, $object.method($arg1, $arg2, ...) and $object.method: $arg1, $args, .... My example uses the latter to avoid more parenthesis.


Comment on Re: [Perl6] Sort a hash by value
Select or Download Code
Re^2: [Perl6] Sort a hash by value
by haoess (Curate) on Dec 12, 2008 at 19:14 UTC
    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 in the spec, and thusly isn't implemented by Rakudo right now.

    Thanks to pmichaud++, now it is (he says).

    Update: Here's his blog entry.

    -- Frank

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://729240]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2015-07-03 18:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (55 votes), past polls