Sort::Key

Sort::Key is the fastest way to sort anything in Perl.
Download

Sort::Key Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Salvador Fandi
  • Publisher web site:
  • http://search.cpan.org/~salva/Net-SFTP-Foreign-1.42/lib/Net/SFTP/Foreign.pm

Sort::Key Tags


Sort::Key Description

Sort::Key is the fastest way to sort anything in Perl. Sort::Key is the fastest way to sort anything in Perl.SYNOPSIS use Sort::Key qw(keysort nkeysort ikeysort); @by_name = keysort { "$_->{surname} $_->{name}" } @people; # sorting by a numeric key: @by_age = nkeysort { $_->{age} } @people; # sorting by a numeric integer key: @by_sons = ikeysort { $_->{sons} } @people;Sort::Key provides a set of functions to sort lists of values by some calculated key value.It is faster (usually much faster) and uses less memory than other alternatives implemented around perl sort function (ST, GRT, etc.).Multikey sorting functionality is also provided via the companion modules Sort::Key::Multi, Sort::Key::Maker and Sort::Key::Register.FUNCTIONSThis module provides a large number of sorting subroutines but they are all variations off the keysort one: @sorted = keysort { CALC_KEY($_) } @datathat is conceptually equivalent to @sorted = sort { CALC_KEY($a) cmp CALC_KEY($b) } @dataand where CALC_KEY($_) can be any expresion to extract the key value from $_ (not only a subroutine call).For instance, some variations are nkeysort that performs a numeric comparison, rkeysort that orders the data in descending order, ikeysort and ukeysort that are optimized versions of nkeysort that can be used when the keys are integers or unsigned integers respectively, etc.Also, inplace versions of the sorters are provided. For instance keysort_inplace { CALC_KEY($_) } @datathat is equivalent to @data = keysort { CALC_KEY($_) } @databut being (a bit) faster and using less memory.The full list of subroutines that can be imported from this module follows:keysort { CALC_KEY } @arrayreturns the elements on @array sorted by the key calculated applying { CALC_KEY } to them.Inside { CALC_KEY }, the object is available as $_.For example: @a=({name=>john, surname=>smith}, {name=>paul, surname=>belvedere}); @by_name=keysort {$_->{name}} @a;This function honours the use locale pragma.nkeysort { CALC_KEY } @arraysimilar to keysort but compares the keys numerically instead of as strings.This function honours the use integer pragma, i.e.: use integer; my @s=(2.4, 2.0, 1.6, 1.2, 0.8); my @ns = nkeysort { $_ } @s; print "@nsn"prints 0.8 1.6 1.2 2.4 2rnkeysort { CALC_KEY } @arrayworks as nkeysort, comparing keys in reverse (or descending) numerical order.ikeysort { CALC_KEY } @arrayworks as keysort but compares the keys as integers (32 bits or more, no checking is performed for overflows).rikeysort { CALC_KEY } @arrayworks as ikeysort, but in reverse (or descending) order.ukeysort { CALC_KEY } @arrayworks as keysort but compares the keys as unsigned integers (32 bits or more).For instance, it can be used to efficiently sort IP4 addresses: my @data = qw(1.2.3.4 4.3.2.1 11.1.111.1 222.12.1.34 0.0.0.0 255.255.255.0) 127.0.0.1); my @sorted = ukeysort { my @a = split /./; (((($a name, $_->middlename }, qw(str str str); Sort::Key::register_type Color => sub { $_->R, $_->G, $_->B }, qw(int int int);Once a datatype has been registered it can be used in the same way as types supported natively, even for defining new types, i.e.: Sort::Key::register_type Family => sub { $_->man, $_->woman }, qw(Person Person);Requirements:· Perl Requirements: · Perl


Sort::Key Related Software