Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 956 Categories, Downloaded 50.326.872 Times

Sort::Key 1.28

  Date Added: January 14, 2010  |  Visits: 1.731

Sort::Key

Report Broken Link
Printer Friendly Version


Product Homepage
Download (94 downloads)

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. FUNCTIONS This module provides a large number of sorting subroutines but they are all variations off the keysort one: @sorted = keysort { CALC_KEY($_) } @data that is conceptually equivalent to @sorted = sort { CALC_KEY($a) cmp CALC_KEY($b) } @data and 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($_) } @data that is equivalent to @data = keysort { CALC_KEY($_) } @data but being (a bit) faster and using less memory. The full list of subroutines that can be imported from this module follows: keysort { CALC_KEY } @array returns 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 } @array similar 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 2 rnkeysort { CALC_KEY } @array works as nkeysort, comparing keys in reverse (or descending) numerical order. ikeysort { CALC_KEY } @array works as keysort but compares the keys as integers (32 bits or more, no checking is performed for overflows). rikeysort { CALC_KEY } @array works as ikeysort, but in reverse (or descending) order. ukeysort { CALC_KEY } @array works 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[0] << 8) + $a[1] << 8) + $a[2] << 8) + $a[3]) } @data; rukeysort { CALC_KEY } @array works as ukeysort, but in reverse (or descending) order. keysort_inplace { CALC_KEY } @array nkeysort_inplace { CALC_KEY } @array ikeysort_inplace { CALC_KEY } @array ukeysort_inplace { CALC_KEY } @array rkeysort_inplace { CALC_KEY } @array rnkeysort_inplace { CALC_KEY } @array rikeysort_inplace { CALC_KEY } @array rukeysort_inplace { CALC_KEY } @array work as the corresponding keysort functions but sorting the array inplace. rsort @array nsort @array rnsort @array isort @array risort @array usort @array rusort @array rsort_inplace @array nsort_inplace @array rnsort_inplace @array isort_inplace @array risort_inplace @array usort_inplace @array rusort_inplace @array are simplified versions of its keysort cousins. They use the own values as the sorting keys. For instance those constructions are equivalent: @sorted = nsort @foo; @sorted = nkeysort { $_ } @foo; @sorted = sort { $a <=> $b } @foo; multikeysorter(@types) multikeysorter_inplace(@types) multikeysorter(≥nkeys, @types) multikeysorter_inplace(≥nkeys, @types) are the low level interface to the multikey sorting functionality (normally, you should use Sort::Key::Maker and Sort::Key::Register or Sort::Key::Multi instead). They get a list of keys descriptions and return a reference to a multikey sorting subroutine. Types accepted by default are: string, str, locale, loc, integer, int, unsigned_integer, uint, number, num and support for additional types can be added via the non exportable register_type subroutine (see below) or the more friendly interface available from Sort::Key::Register. Types can be preceded by a minus sign to indicate descending order. If the first argument is a reference to a subroutine it is used as the multikey extraction function. If not, the generated sorters expect one as their first argument. Example: my $sorter1 = multikeysorter(sub {length $_, $_}, qw(int str)); my @sorted1 = &$sorter1(qw(foo fo o of oof)); my $sorter2 = multikeysorter(qw(int str)); my @sorted2 = &$sorter2(sub {length $_, $_}, qw(foo fo o of oof)); Sort::Key::register_type($name, ≥nsubkeys, @subkeystypes) registers a new datatype named $name defining how to convert it to a multikey. ≥nsubkeys should convert the object of type $name passed on $_ to a list of values composing the multikey. @subkeystypes is the list of types for the generated multikeys. For instance: Sort::Key::register_type Person => sub { $_->surname, $_->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: No special requirements
Platforms: Linux
Keyword: Array Calc Data Key Libraries Name Programming Qw Sort Sortkey
Users rating: 0/10

License: Freeware Size: 56.32 KB
SORT::KEY RELATED
Libraries  -  Tie::Array::RestrictUpdates 0.01
Tie::Array::RestrictUpdates can limit the number of times you change elements in an array. SYNOPSIS use Tie::Array::RestrictUpdates; tie @foo,"Tie::Array::RestrictUpdates",1; # Default limit is 1. # Every element from the array can only be...
3.07 KB  
Libraries  -  Numarray 1.4.0
Numarray provides array manipulation and computational capabilities similar to those found in IDL, Matlab, or Octave. Using numarray, it is possible to write many efficient numerical data processing applications directly in Python without using...
1.1 MB  
Libraries  -  Text::MicroMason::Functions 1.992
Text::MicroMason::Functions Perl module contains Function Exporter for Simple Mason Templates. SYNOPSIS Use the execute function to parse and evalute a template: use Text::MicroMason::Functions qw( execute ); print execute($template,...
69.63 KB  
Libraries  -  GDS2 2.09a
GDS2 is a module for quickly creating programs to read and/or write GDS2 files. Create Method new - open gds2 file usage: my $gds2File = new GDS2(-fileName => "filename.gds2"); ## to read my $gds2File2 = new GDS2(-fileName =>...
10.24 KB  
Development Editors  -  Windows Phone 7 Training Kit for Developers RTM
This Windows Phone 7 Training Kit will give you a jumpstart into the new Windows Phone world by providing you with a step-by-step explanation of the tools to use and some key concepts for programming Windows Phones. Windows Phone 7 Series...
 
Development Editors  -  Windows Phone 7.5 Training Kit for Developers New
This Windows Phone 7 Training Kit will give you a jumpstart into the new Windows Phone world by providing you with a step-by-step explanation of the tools to use and some key concepts for programming Windows Phones. Windows Phone 7 Series...
 
Libraries  -  Tie::Array::PackedC 0.03
Tie::Array::PackedC is a tie a Perl array to a C-style array (packed; elements of a single, simple data type). SYNOPSIS use Tie::Array::PackedC qw(packed_array packed_array_string); my $ref=packed_array(1,2,3,4); my...
6.14 KB  
Libraries  -  Data::PropertyList 1998.1217
Data::PropertyList is a Perl module that can convert arbitrary objects to/from strings. SYNOPSIS use Data::PropertyList qw(astext fromtext); $hash_ref = { items => [ 7 .. 11 ], key => value }; $string = astext($hash_ref); # ... $hash_ref...
8.19 KB  
Libraries  -  Data::Inherited 1.00
Data::Inherited is a Perl module with hierarchy-wide accumulation of list and hash results. SYNOPSIS package Foo; use base Data::Inherited; use constant PROPERTIES => (qw/name address/); package Bar; use base Foo; use constant PROPERTIES...
12.29 KB  
Libraries  -  Color::Calc 1.04
Color::Calc provides a module which implements simple calculations with RGB colors. This can be used to create a full color scheme from a few colors. There are three methods to use the calculation functions: You can create an object, import...
11.26 KB  
NEW DOWNLOADS IN PROGRAMMING, LIBRARIES
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  Math::GMPf 0.29
Math::GMPf - perl interface to the GMP library's floating point (mpf) functions.
30.72 KB  
Programming  -  Net::Wire10 1.08
Net::Wire10 is a Pure Perl connector that talks to Sphinx, MySQL and Drizzle servers. Net::Wire10 implements the low-level network protocol, alias the MySQL wire protocol version 10, necessary for talking to one of the aforementioned...
30.72 KB  
Programming  -  logilab-common 0.56.2
a bunch of modules providing low level functionnalities shared among some python projects devel Please note that some of the modules have some extra dependencies. For instance, logilab.common.db will require a db-api 2.0 compliant...
174.08 KB  
Programming  -  OpenSSL for linux 1.0.0a
The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a...
3.83 MB  
Libraries  -  wolfSSL 4.0.0
The wolfSSL embedded SSL/TLS library is a lightweight SSL library written in ANSI standard C and targeted for embedded and RTOS environments - primarily because of its small size, speed, and feature set. It is commonly used in standard operating...
3.88 MB  
Libraries  -  EuGTK 4.8.9
Makes it easy to develop good- looking, fast, cross-platform programs that run on Linux, OS X, and Windows. Euphoria is a very fast interpreted/compiled language with straight-forward syntax. EuGTK allows programming in a clean, object-oriented...
10.68 MB  
Libraries  -  Linux User Group Library Manager 1.0
The LUG Library Manager is a project to help Linux User Groups start their own library. A LUG library is helpful to the community at large because it increases access to information, and gives everyone the opportunity to become more knowledgeable.
5.35 KB  
Libraries  -  Module::MakefilePL::Parse 0.12
Module::MakefilePL::Parse is a Perl module to parse required modules from Makefile.PL. SYNOPSIS use Module::MakefilePL::Parse; open $fh, Makefile.PL; $parser = Module::MakefilePL::Parse->new( join("", ) ); $info = $parser->required;...
8.19 KB  
Libraries  -  sqlpp 0.06
sqlpp Perl package is a SQL preprocessor. sqlpp is a conventional cpp-alike preprocessor taught to understand SQL ( PgSQL, in particular) syntax specificities. In addition to the standard #define/#ifdef/#else/#endif cohort, provides also...
10.24 KB