

o  numeric substrings are compared numerically 
o  alphabetic substrings are compared lexically 
o  numeric substrings come always before alphabetic substrings 
Note, that the sorting is case sensitive. To do a case insensitive sort you have to convert the keys explicitly:
my @sorted = natkeysort { lc $_ } @data
Also, once this module is loaded, the new type natural (or nat) will be available from Sort::Key::Maker. For instance:
use Sort::Key::Natural; use Sort::Key::Maker i_rnat_keysort => qw(integer natural);
creates a multikey sorter i_rnat_keysort accepting two keys, the first to be compared as an integer and the second in natural descending order.
There is also an alternative set of natural sorting functions that recognize floating point numbers. They use the key type natwf (abbreviation of natural_with_floats).
the functions that can be imported from this module are:
natsort @data returns the elements of @data sorted in natural order. rnatsort @data returns the elements of @data sorted in natural descending order. natkeysort { CALC_KEY($_) } @data returns the elements on @array naturally sorted by the keys resulting from applying them CALC_KEY. rnatkeysort { CALC_KEY($_) } @data is similar to natkeysort but sorts the elements in descending order. natsort_inplace @data rnatsort_inplace @data natkeysort_inplace { CALC_KEY($_) } @data rnatkeysort_inplace { CALC_KEY($_) } @data these functions are similar respectively to natsort, rnatsort, natsortkey and rnatsortkey, but they sort the array @data in place. $key = mkkey_natural $string given $string, returns a key that can be compared lexicographically to another key obtained in the same manner, results in the same order as comparing the former strings as in the natural order. If the argument $key is not provided it defaults to $_.
natwfsort @data rnatwfsort @data natwfkeysort { CALC_KEY($_) } @data rnatwfkeysort { CALC_KEY($_) } @data natwfsort_inplace @data rnatwfsort_inplace @data natwfkeysort_inplace { CALC_KEY($_) } @data rnatwfkeysort_inplace { CALC_KEY($_) } @data mkkey_natural_with_floats $key this ugly named set of functions perform in the same way as its s/natwf/nat/ counterpart with the difference that they honor floating point numbers embedded inside the strings. In this context a floating point number is a string matching the regular expression /[+\]?\d+(\.\d*)?/. Note that numbers with an exponent part (i.e. 1.12E12) are not recognized as such.
Note also that numbers without an integer part (i.e. .2 or .12) are not supported either.
Sort::Key, Sort::Key::Maker.Other module providing similar functionality is Sort::Naturally.
Copyright (C) 2006, 2012, 2014 by Salvador Fandinõ, <sfandino@yahoo.com>.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.
perl v5.20.3  SORT::KEY::NATURAL (3)  20140429 
Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.