The results of Sort::Naturally were not what I expected. For example, "AZZZ3827Q" sorts ahead of "A1".
I don't believe the natural sorting definition used here is the one most commonly used, and although the author explains his definition, I don't believe it's correct. Other natural sorting algorithms (for example the one in the Macintosh Finder, or Sort::Key::Naturally) do it the other way: they divide the string into alphabetic and numeric components and then compare the components, rather than comparing individual characters.
This is one of those modules that does only one thing and does it well: compare numeric substrings as numbers, and characters as characters. You "use" it, replace "sort" with "nsort", and it works like a charm. Nice!
Aaron wrote in his review that 'The results of Sort::Naturally were not what I expected. For example, "AZZZ3827Q" sorts ahead of "A1".'
The rationale for this is documented on the module's POD:
"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."
Even the synopsis code already presents this to the potential user, ordering elements as:
So I really don't understand the poor rating. That said, the documentation for this module *can* be a little too confusing for such a simple purpose and contains a few typos. There is even (by the time of this writing) a two-year old ticket regarding them, which is why I gave this module 4 stars for documentation.
Sort::Naturally helped me get rid of about 25 lines of hard-to-read code sorting complex alphanumeric strings. nsort worked perfectly out of the box, without my needing to worry about configuration or special options.
A very easy to use module that does what you would naturally consider right ( naturally meaning what you most likely have been taught to do). Don't bother writing your own sorting if this one fits the bill.
A look at the code shows a strange construct but I guess the author had good reasons (speed?). Anyway I'm interrested in how to use it not how it is build and using it is simple.