Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: sorting a list of hashes on an element/attribute of the hash

by princepawn (Parson)
on Jun 04, 2007 at 17:04 UTC ( #619175=note: print w/ replies, xml ) Need Help??


in reply to sorting a list of hashes on an element/attribute of the hash

For small data sets, the answers given are readable and to the point. However, Sort::Key is just as readable and the fastest Perl sorting solution --- ideal if you have a large data set:

use Sort::Key ; # sorting by a numeric integer key: @by_order = ikeysort { $_->{order} } @$data;


Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality


Comment on Re: sorting a list of hashes on an element/attribute of the hash
Download Code
Re^2: sorting a list of hashes on an element/attribute of the hash
by salva (Abbot) on Jun 04, 2007 at 17:43 UTC
    Well, I am currently working on Sort::Key::Radix that uses a Radix Sort as the sorting algorithm and has identical usage to Sort::Key.

    When sorting large data sets and for some kinds of data, as for instance small numbers (as shown on the OP), it can be much faster than Sort::Key.

    use Sort::Key::Radix qw(ukeysort); my @by_order = ukeysort { $_->{order} } @data;

    ...though I am still getting some FAIL reports from the CPAN testers.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2015-07-06 23:33 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 (85 votes), past polls