Is Sort:Naturally a Little Off?
[email protected] (Shawn H Corey) Fri, 24 Sep 2021 13:46:24 -0400
| Newsgroups | perl.module-authors |
|---|---|
| Message-ID | <[email protected]> |
--------------4A15EA13CB37990DC1BFEF99
Content-Type: multipart/alternative;
boundary="------------809D5B38B45708C1B337E806"
--------------809D5B38B45708C1B337E806
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
I was testing different sort routines and I think I stopped a bug in
Sort::Naturally (see attached script). It's output is:
unsorted : 4 A X i 1 x 10 a B ä y z į C Ä b c Į Y Z än and
ÄND And Any ant Äm Äs
no locale, perl : 1 10 4 A And Any B C X Y Z a and ant b c i x y z
Ä ÄND Äm Äs ä än Į į
no locale, naturally : 1 4 10 A a ä Äm And and Ä än ÄND ant Any Äs B b
C c i Į į X x Y y Z z
use locale, perl : 1 10 4 A a Ä ä Äm än And and ÄND ant Any Äs B b
C c i Į į X x Y y Z z
use locale, naturally : 1 4 10 A a ä Äm And and Ä än ÄND ant Any Äs B b
C c i Į į X x Y y Z z
use locale, perl num : 1 4 10 A a Ä ä Äm än And and ÄND ant Any Äs B b
C c i Į į X x Y y Z z
Is the Ä out of place for the Sort::Naturally line?
--------------809D5B38B45708C1B337E806
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>I was testing different sort routines and I think I stopped a bug
in Sort::Naturally (see attached script). It's output is:</p>
<p><font face="monospace">unsorted : 4 A X i 1 x 10 a B
ä y z į C Ä b c Į Y Z än and ÄND And Any ant Äm Äs<br>
<br>
no locale, perl : 1 10 4 A And Any B C X Y Z a and ant b c
i x y z Ä ÄND Äm Äs ä än Į į<br>
no locale, naturally : 1 4 10 A a ä Äm And and Ä än ÄND ant Any
Äs B b C c i Į į X x Y y Z z<br>
<br>
use locale, perl : 1 10 4 A a Ä ä Äm än And and ÄND ant Any
Äs B b C c i Į į X x Y y Z z<br>
use locale, naturally : 1 4 10 A a ä Äm And and Ä än ÄND ant Any
Äs B b C c i Į į X x Y y Z z<br>
<br>
use locale, perl num : 1 4 10 A a Ä ä Äm än And and ÄND ant Any
Äs B b C c i Į į X x Y y Z z<br>
</font></p>
<p>Is the Ä out of place for the Sort::Naturally line?<br>
</p>
</body>
</html>
--------------809D5B38B45708C1B337E806--
--------------4A15EA13CB37990DC1BFEF99
Content-Type: application/x-perl;
name="sort-test.pl"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment;
filename="sort-test.pl"
#!/usr/bin/env perl
use strict;
use warnings;
use autodie;
use feature qw( :all );
use utf8;
use Sort::Naturally;
use lib glob('~/perl5/lib');
use MyUtils qw( vardump );
my @list = qw(
4 A X i 1 x 10 a B ä y z į C Ä b c Į Y Z
än and
ÄND
And
Any
ant
Äm Äs
);
say "unsorted : @list";
say '';
{
no locale;
my @sorted = sort @list;
say "no locale, perl : @sorted";
@sorted = nsort @list;
say "no locale, naturally : @sorted";
say '';
}
{
use locale;
my @sorted = sort @list;
say "use locale, perl : @sorted";
@sorted = nsort @list;
say "use locale, naturally : @sorted";
say '';
}
{
use locale;
use Scalar::Util qw( looks_like_number );
sub mycmp {
if( looks_like_number( $a ) && looks_like_number( $b ) ){
return $a <=> $b || $a cmp $b;
}else{
return $a cmp $b;
}
}
my @sorted = sort mycmp @list;
say "use locale, perl num : @sorted";
say '';
}
--------------4A15EA13CB37990DC1BFEF99--