Sort-Naturally
view release on metacpan or search on metacpan
Revision history for Perl module Sort::Naturally
2012-04-11 bingos bingos@cpan.org
* release 1.03 -- modernise the distribution
2004-12-29 Sean M. Burke sburke@cpan.org
* Release 1.02 -- just rebundling, no code changes
2001-05-25 Sean M. Burke sburke@cpan.org
Makefile.PL view on Meta::CPAN
META_MERGE => {
resources => {
repository => 'https://github.com/bingos/sort-naturally',
},
},
#BUILD_REQUIRES => {
#},
'AUTHOR' => 'Sean M. Burke <sburke@cpan.org>',
'ABSTRACT' => 'sort lexically, but sort numeral parts numerically',
'NAME' => 'Sort::Naturally',
'VERSION_FROM' => 'lib/Sort/Naturally.pm', # finds $VERSION
'dist' => { COMPRESS => 'gzip -6f', SUFFIX => 'gz', },
);
sub WriteMakefile1 { #Written by Alexandr Ciornii, version 0.21. Added by eumm-upgrade.
my %params=@_;
my $eumm_version=$ExtUtils::MakeMaker::VERSION;
$eumm_version=eval $eumm_version;
die "EXTRA_META is deprecated" if exists $params{EXTRA_META};
README for Sort::Naturally
Time-stamp: "2001-05-25 21:17:33 MDT"
Sort::Naturally
[extracted from the Pod...]
NAME
Sort::Naturally -- sort lexically, but sort numeral parts
numerically
SYNOPSIS
@them = nsort(qw(
foo12a foo12z foo13a foo 14 9x foo12 fooa foolio Foolio Foo12a
));
print join(' ', @them), "\n";
Prints:
lexically, case-insensitively: "Foo" comes between
"fish" and "fowl".
o Numeric substrings are sorted numerically: "100" comes
after "20", not before.
o \W substrings (neither words-characters nor digits) are
ignored.
o Our use of \w, \d, \D, and \W is locale-sensitive:
Sort::Naturally uses a use locale statement.
o When comparing two strings, where a numeric substring
in one place is not up against a numeric substring in
another, the non-numeric always comes first. This is
fudged by reading pretending that the lack of a number
substring has the value -1, like so:
foo => "foo", -1
foobar => "foo", -1, "bar"
foo13 => "foo", 13,
are not seen. If your data has thousands separators in
numbers ("20,000 Leagues Under The Sea" or "20.000
lieues sous les mers"), consider stripping them before
feeding them to nsort or ncmp.
[end Pod extract]
INSTALLATION
You install Sort::Naturally, as you would install any perl module
library, by running these commands:
perl Makefile.PL
make
make test
make install
If you want to install a private copy of Sort::Naturally in your home
directory, then you should try to produce the initial Makefile with
something like this command:
perl Makefile.PL LIB=~/perl
See perldoc perlmodinstall for more information on installing modules.
DOCUMENTATION
POD-format documentation is included in Naturally.pm. POD is readable
with the 'perldoc' utility. See ChangeLog for recent changes.
SUPPORT
Questions, bug reports, useful code bits, and suggestions for
Sort::Naturally should just be sent to me at sburke@cpan.org
AVAILABILITY
The latest version of Sort::Naturally is available from the
Comprehensive Perl Archive Network (CPAN). Visit
<http://www.perl.com/CPAN/> to find a CPAN site near you.
COPYRIGHT
Copyright 2001, Sean M. Burke <sburke@cpan.org>, all rights
reserved.
The programs and documentation in this dist are distributed in
lib/Sort/Naturally.pm view on Meta::CPAN
require 5;
package Sort::Naturally; # Time-stamp: "2004-12-29 18:30:03 AST"
$VERSION = '1.03';
@EXPORT = ('nsort', 'ncmp');
require Exporter;
@ISA = ('Exporter');
use strict;
use locale;
use integer;
#-----------------------------------------------------------------------------
lib/Sort/Naturally.pm view on Meta::CPAN
undef &maker;
#-----------------------------------------------------------------------------
1;
############### END OF MAIN SOURCE ###########################################
__END__
=head1 NAME
Sort::Naturally -- sort lexically, but sort numeral parts numerically
=head1 SYNOPSIS
@them = nsort(qw(
foo12a foo12z foo13a foo 14 9x foo12 fooa foolio Foolio Foo12a
));
print join(' ', @them), "\n";
Prints:
lib/Sort/Naturally.pm view on Meta::CPAN
Numeric substrings are sorted numerically:
"100" comes after "20", not before.
=item *
\W substrings (neither words-characters nor digits) are I<ignored>.
=item *
Our use of \w, \d, \D, and \W is locale-sensitive: Sort::Naturally
uses a C<use locale> statement.
=item *
When comparing two strings, where a numeric substring in one
place is I<not> up against a numeric substring in another,
the non-numeric always comes first. This is fudged by
reading pretending that the lack of a number substring has
the value -1, like so:
lib/Sort/Naturally.pm view on Meta::CPAN
...or even in a Schwartzian transform, like this:
@strings =
map $_->[0]
sort { $a->[1] cmp $b->[1] }
map { [$_, make_a_sort_key_from($_) ]
@_
;
...you wight want something that replaces not C<sort>, but C<cmp>.
That's what Sort::Naturally's C<ncmp> function is for. Call it with
the syntax C<ncmp($left,$right)> instead of C<$left cmp $right>,
but otherwise it's a fine replacement:
@objects_sorted = sort { ncmp($a->tag,$b->tag) } @objects;
@strings =
map $_->[0]
sort { ncmp($a->[1], $b->[1]) }
map { [$_, make_a_sort_key_from($_) ]
@_
t/00_about_verbose.t view on Meta::CPAN
require 5;
# Time-stamp: "2004-12-29 20:53:16 AST"
# Summary of, well, things.
use Test;
BEGIN {plan tests => 2};
ok 1;
use Sort::Naturally ();
#chdir "t" if -e "t";
{
my @out;
push @out,
"\n\nPerl v",
defined($^V) ? sprintf('%vd', $^V) : $],
" under $^O ",
(defined(&Win32::BuildNumber) and defined &Win32::BuildNumber())
t/01_old_junk.t view on Meta::CPAN
# Time-stamp: "2004-12-29 18:29:18 AST"
use strict;
use Test;
# use a BEGIN block so we print our plan before MyModule is loaded
BEGIN { plan tests => 21 }
ok(1);
#sub Sort::Naturally::DEBUG () {0}
use Sort::Naturally;
print "# Perl v$], Sort::Naturally v$Sort::Naturally::VERSION\n#\n";
sub shuffle {
my @out;
while(@_) { push @out, splice @_, rand(@_), 1 };
return @out
}
my $ok1 = '9x 14 foo fooa foolio Foolio foo12 foo12a Foo12a foo12z foo13a';
my $ok2 = '9x 14 foo fooa Foolio foolio foo12 Foo12a foo12a foo12z foo13a';
( run in 1.307 second using v1.01-cache-2.11-cpan-56fb94df46f )