Subject: | Non-numeric word-character substrings (of mixed sort strings) are sorted incorrectly |
Date: | Fri, 8 Jun 2012 02:51:49 -0700 |
To: | "bug-Sort-Naturally [...] rt.cpan.org" <bug-Sort-Naturally [...] rt.cpan.org> |
From: | "Winterbottom, Nigel" <nigel.winterbottom [...] fluke.com> |
Distribution name and version : Sort-Naturally-1.03
Perl version : This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi (with 40 registered patches, see perl -V for more detail)
Operating System vendor and version : Linux Comark-Nigel 2.6.35-32-generic #67-Ubuntu SMP Mon Mar 5 19:39:49 UTC 2012 x86_64 GNU/Linux
My application is sorting Electronic Circuit References (Capacitors Resistors etc. e.g. C1, C11, CR1). The bug is easily demonstrated using a modification of the documented example. ( I added "fo12" to the list )
#BUG DEMONSTRATION
@them = nsort(qw(
foo12a foo12z foo13a foo 14 9x fo12 foo12 fooa foolio Foolio Foo12a
));
print join(' ', @them), "\n";
PRINTS:
9x 14 foo fooa foolio Foolio foo12 foo12a Foo12a foo12z foo13a fo12
I think "fo12" should come before "foo12".
#FIX
Looking at the code I spotted a possible typo, in that the comment does not agree with the code. Having fixed that up I get the following output from the above example:
9x 14 fo12 foo foo12 foo12a Foo12a foo12z foo13a fooa foolio Foolio
I am much happier with that result.
#PATCH
diff Sort/Naturally-1.03.pm Sort/Naturally.pm
72c72
< $x2 = $y2 if $x2 > $y2;
---
Show quoted text
> $x2 = $y2 if $x2 < $y2;
--
Regards
Nigel Winterbottom - Senior Engineer - Comark Instruments
DDI: +44 (0)1462 444232 <http://www.comarkltd.com>
Comark House, Bury Mead Road, Hitchin, Herts, UK. SG5 1RT