Sort::Key - Perl extension for sorting objects by some key
use Sort::Key; @by_name = keysort { "$_->{surname} $_->{name}" } @people; @by_age = nkeysort { $_->{age} } @people; @by_sons = ikeysort { $_->{sons} } @people;
Sort::Key provides a set of functions to sort object arrays by some (calculated) key value.
Usually, it is faster and uses less memory than other alternatives implemented around perl sort function.
This package exports these functions:
sorts @array by the key calculated applying { CALC_KEY }.
@array
{ CALC_KEY }
Inside { CALC_KEY }, the object is available as $_.
$_
For example:
@a=({name=>john, surname=>smith}, {name=>paul, surname=>belvedere}); @by_name=keysort {$_->{name}} @a;
similar to keysort but takes into account locale configuration when comparing keys.
similar to keysort but compares the keys numerically instead of as strings.
similar to keysort but automatically converts the keys to integer values and compares them numerically.
perl sort function
Salvador Fandiño, <sfandino@yahoo.com>
Copyright (C) 2005 by Salvador Fandiño
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.
To install Sort::Key, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sort::Key
CPAN shell
perl -MCPAN -e shell install Sort::Key
For more information on module installation, please visit the detailed CPAN module installation guide.