Sort::Key::Top

Sort::Key::Top is a Perl module that can select and sort top n elements.
Download

Sort::Key::Top 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::Top Tags


Sort::Key::Top Description

Sort::Key::Top is a Perl module that can select and sort top n elements. Sort::Key::Top is a Perl module that can select and sort top n elements.SYNOPSIS use Sort::Key::Top (nkeytop top); # select 5 first numbers by absolute value: @top = nkeytop { abs $_ } 5 => 1, 2, 7, 5, 5, 1, 78, 0, -2, -8, 2; # ==> @top = (1, 2, 1, 0, -2) # select 5 first words by lexicographic order: @a = qw(cat fish bird leon penguin horse rat elephant squirrel dog); @top = top 5 => @a; # ==> @top = qw(cat fish bird elephant dog);The functions available from this module select the top n elements from a list using several common orderings and custom key extraction procedures.They are all variations around keytopsort { CALC_KEY($_) } $n => @data;This function calculates the ordering key for every element in @data using the expression inside the block. Then it selects and orders the $n elements with the lower keys when compared lexicographically.It is equivalent to the pure Perl expression: (sort { CALC_KEY($a) cmp CALC_KEY($b) } @data);Variations allow to:- use the own values as the ordering keys topsort 5 => qw(a b ab t uu g h aa aac); ==> a aa aac ab b- return the selected values in the original order top 5 => qw(a b ab t uu g h aa aac); ==> a b ab aa aac- use a different orderingFor instance comparing the keys as numbers, using the locale configuration or in reverse order: rnkeytop { length $_ } 3 => qw(a ab aa aac b t uu g h); ==> ab aa aac rnkeytopsort { length $_ } 3 => qw(a ab aa aac b t uu g h); ==> aac ab aaA prefix is used to indicate the required ordering:(no prefix)lexicographical ascending orderrlexicographical descending orderllexicographical ascending order obeying locale configurationrlexicographical descending order obeying locale configurationnnumerical ascending orderrnnumerical descending orderinumerical ascending order but converting the keys to integers firstrinumerical descending order but converting the keys to integers firstunumerical ascending order but converting the keys to unsigned integers firstrunumerical descending order but converting the keys to unsigned integers firstThe full list of available functions is: top ltop ntop itop utop rtop rltop rntop ritop rutop keytop lkeytop nkeytop ikeytop ukeytop rkeytop rlkeytop rnkeytop rikeytop rukeytop topsort ltopsort ntopsort itopsort utopsort rtopsort rltopsort rntopsort ritopsort rutopsort keytopsort lkeytopsort nkeytopsort ikeytopsort ukeytopsort rkeytopsort rlkeytopsort rnkeytopsort rikeytopsort rukeytopsort Requirements: · Perl


Sort::Key::Top Related Software