Skip Menu |
 

This queue is for tickets about the Sort-Naturally CPAN distribution.

Report information
The Basics
Id: 77701
Status: open
Priority: 0/
Queue: Sort-Naturally

People
Owner: Nobody in particular
Requestors: nigel.winterbottom [...] fluke.com
tsibley [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



X-Forefront-Antispam-Report: CIP:192.65.41.20;KIP:(null);UIP:(null);IPV:NLI;H:igate.tek.com;RD:igate.tek.com;EFVD:NLI
From nigel.winterbottom [...] fluke.com Fri Jun 8 05: 52:06 2012
MIME-Version: 1.0
X-Spam-Status: No, score=-6.9 tagged_above=-99.9 required=10 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5] autolearn=ham
X-Bigfish: VPS0(zzzz1202hzz8275bhz2dh668h839h944hd25hf0ah)
X-Spam-Flag: NO
Acceptlanguage: en-US
Content-Language: en-GB
content-type: text/plain; charset="utf-8"
Message-ID: <6A1F1690AEA54449AD8DC16D9FDF3A6768505D2F7F [...] us-bv-m10.global.tektronix.net>
X-Virus-Scanned: Debian amavisd-new at bestpractical.com
X-MS-Tnef-Correlator:
X-Spam-Score: -6.9
Received: from localhost (localhost [127.0.0.1]) by hipster.bestpractical.com (Postfix) with ESMTP id 6EF3C240396 for <cpan-bug+Sort-Naturally [...] hipster.bestpractical.com>; Fri, 8 Jun 2012 05:52:06 -0400 (EDT)
Received: from hipster.bestpractical.com ([127.0.0.1]) by localhost (hipster.bestpractical.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DvCpxNtkGDXX for <cpan-bug+Sort-Naturally [...] hipster.bestpractical.com>; Fri, 8 Jun 2012 05:52:03 -0400 (EDT)
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by hipster.bestpractical.com (Postfix) with SMTP id 01436240124 for <bug-Sort-Naturally [...] rt.cpan.org>; Fri, 8 Jun 2012 05:52:02 -0400 (EDT)
Received: (qmail 9772 invoked by uid 103); 8 Jun 2012 09:52:01 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 8 Jun 2012 09:52:01 -0000
Received: from tx2ehsobe001.messaging.microsoft.com (HELO tx2outboundpool.messaging.microsoft.com) (65.55.88.11) by 16.mx.develooper.com (qpsmtpd/0.80/v0.80-19-gf52d165) with ESMTP; Fri, 08 Jun 2012 02:51:56 -0700
Received: from mail131-tx2-R.bigfish.com (10.9.14.254) by TX2EHSOBE010.bigfish.com (10.9.40.30) with Microsoft SMTP Server id 14.1.225.23; Fri, 8 Jun 2012 09:51:03 +0000
Received: from mail131-tx2 (localhost [127.0.0.1]) by mail131-tx2-R.bigfish.com (Postfix) with ESMTP id 5EA3426011B for <bug-Sort-Naturally [...] rt.cpan.org>; Fri, 8 Jun 2012 09:51:03 +0000 (UTC)
Received: from mail131-tx2 (localhost.localdomain [127.0.0.1]) by mail131-tx2 (MessageSwitch) id 1339149061712924_26513; Fri, 8 Jun 2012 09:51:01 +0000 (UTC)
Received: from TX2EHSMHS023.bigfish.com (unknown [10.9.14.245]) by mail131-tx2.bigfish.com (Postfix) with ESMTP id A9F283A0047 for <bug-Sort-Naturally [...] rt.cpan.org>; Fri, 8 Jun 2012 09:51:01 +0000 (UTC)
Received: from igate.tek.com (192.65.41.20) by TX2EHSMHS023.bigfish.com (10.9.99.123) with Microsoft SMTP Server id 14.1.225.23; Fri, 8 Jun 2012 09:52:05 +0000
Received: from tektronix.tek.com (tektronix.tek.com [128.181.6.43]) by igate.tek.com (8.13.8+Sun/8.13.8) with ESMTP id q589pp4o008112 for <bug-Sort-Naturally [...] rt.cpan.org>; Fri, 8 Jun 2012 02:51:51 -0700 (PDT)
Received: from us-bv-m04.global.tektronix.net (us-bv-m04.global.tektronix.net [128.181.2.117]) by tektronix.tek.com (8.13.8+Sun/8.13.8) with SMTP id q589pobL014767 for <bug-Sort-Naturally [...] rt.cpan.org>; Fri, 8 Jun 2012 02:51:51 -0700 (PDT)
Received: from us-bv-m10.global.tektronix.net ([128.181.2.45]) by us-bv-m04.global.tektronix.net ([128.181.2.117]) with mapi; Fri, 8 Jun 2012 02:51:50 -0700
Delivered-To: cpan-bug+Sort-Naturally [...] hipster.bestpractical.com
Subject: Non-numeric word-character substrings (of mixed sort strings) are sorted incorrectly
Return-Path: <nigel.winterbottom [...] fluke.com>
Thread-Index: AQHNRVxT+DaHcAZk0k+qwzGfpHYPng==
X-RT-Mail-Extension: sort-naturally
X-Original-To: cpan-bug+Sort-Naturally [...] hipster.bestpractical.com
X-Spam-Check-BY: 16.mx.develooper.com
Date: Fri, 8 Jun 2012 02:51:49 -0700
X-Originatororg: fluke.com
X-Spam-Level:
X-MS-Has-Attach:
Thread-Topic: Non-numeric word-character substrings (of mixed sort strings) are sorted incorrectly
Accept-Language: en-US
To: "bug-Sort-Naturally [...] rt.cpan.org" <bug-Sort-Naturally [...] rt.cpan.org>
X-Spamscore: 0
Content-Transfer-Encoding: quoted-printable
From: "Winterbottom, Nigel" <nigel.winterbottom [...] fluke.com>
X-RT-Original-Encoding: us-ascii
Content-Length: 1402
Download (untitled) / with headers
text/plain 1.3k
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
MIME-Version: 1.0
In-Reply-To: <6A1F1690AEA54449AD8DC16D9FDF3A6768505D2F7F [...] us-bv-m10.global.tektronix.net>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <6A1F1690AEA54449AD8DC16D9FDF3A6768505D2F7F [...] us-bv-m10.global.tektronix.net>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-14641-1408643462-1847.77701-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 1439
Download (untitled) / with headers
text/plain 1.4k
On Fri Jun 08 02:52:07 2012, nigel.winterbottom@fluke.com wrote: Show quoted text
> 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; > ---
> > $x2 = $y2 if $x2 < $y2;
The comment you reference is: # Now make x2 the min length of the two: and the original code is indeed correctly described by the comment. $x2 is set to $y2 if and only if $x2 is greater than $y2, i.e. $y2 is less than $x2. If $x2 is already the smaller number, then it is left alone. If $x2 is the larger number, it it set to the smaller number in $y2. This makes $x2 the minimum. It's easy enough to try it out and see for yourself: $ perl -E '($x, $y) = @ARGV; $x = $y if $x > $y; say $x;' 7 5 5 $ perl -E '($x, $y) = @ARGV; $x = $y if $x > $y; say $x;' 5 7 5 Your desired sort order matches what would be output if numerics always came before alphabetics, instead of only coming before when at the start of the string. I do think there's a bug here, in that the sort order: 9x 14 foo fooa foolio Foolio foo12 foo12a Foo12a foo12z foo13a fo12 puts the shorter strings "fo12" and "foo12" after longer strings.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.