Monks,

I've been trying to learn a bit more about sorting, but was having problems with 'A brief tutorial on Perl's native sorting facilities' A brief tutorial on Perl's native sorting facilities. by BrowserUk.
The desc and examples looked just fine and I seemed to understand it, but couldn't reproduce it...
After some experimentation and inspiration I discovered the following:

From perldocs:

#!/usr/bin/perl -w use strict; use locale; print +(sort grep /\w/, map { chr } 0..255), "\n"; no locale; print +(sort grep /\w/, map { chr } 0..255), "\n";
produced this:
_0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz

My test prog

#!/usr/bin/perl -w use strict; my ( @arr1 ); # GRT # Sort by num, then letter use locale; print "locale\n"; @arr1 = map{ unpack 'x[NA1]A*', $_ } sort map{ pack 'NA1 A*', substr( $_, 1 ), substr( $_, 0, 1 ), $_ } qw[ A473 B437 B659 C659 C123 D123 D222 E222 E001 A001 ]; print join("\n", @arr1)."\n\n"; no locale; print "no locale\n"; @arr1 = map{ unpack 'x[NA1]A*', $_ } sort map{ pack 'NA1 A*', substr( $_, 1 ), substr( $_, 0, 1 ), $_ } qw[ A473 B437 B659 C659 C123 D123 D222 E222 E001 A001 ]; print join("\n", @arr1)."\n";
Outputs:

locale A001 A473 B437 B659 C123 C659 D123 D222 E001 E222 no locale A001 E001 C123 D123 D222 E222 B437 A473 B659 C659

It seems to me that regardless of locale/no locale, it should sort nums before letters, as per BrowserUK's tutorial.
FYI:
perl v5.8.8, Linux openSUSE 10.2 (i586) 2.6.18.2-34-bigsmp

Also: env|grep -i lc has no output, set|grep -i lc gives:

MAILCHECK=60 MODLIST=($(LC_ALL=C $YAST -l| grep '^[a-z]' | grep -v "Availab +le")); done <<(LC_ALL=C $YAST $mod $prev help 2>&1); done <<(LC_ALL=C $YAST $mod help 2>&1); test_lc () for lc in LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY +LC_MESSAGES LC_PAPER LC_NAMELC_ADDRESS LC_TELEPHONE LC_MEASUREMENT LC +_IDENTIFICATION LC_ALL; eval val="\$$lc"; unset lc val; unset lc val;

Cheers
Chris

20071129 Janitored by Corion: Localized link


In reply to Sorting (GRT) and locale issues by chrism01

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.