It seems to me that regardless of locale/no locale, it should sort nums before letters, as per BrowserUK's tutorial.

What numbers? You don't provide any numbers to sort. You first convert the numbers into strings of 4 characters. The resulting characters could be anything, including letters. sort is doing a lexical sort on them as requested, and applies locale rules as requested even though it makes no sense to do so.

In this specific case, locale could very well affect how "µ" and "Ù" sort.

my $NUL     = chr(0x00);
my $SOH     = chr(0x01);
my $STX     = chr(0x02);
my $undef93 = chr(0x93);

001: "${NUL}${NUL}${NUL}${SOH}"
123: "${NUL}${NUL}${NUL}{"
222: "${NUL}${NUL}${NUL}Þ"
437: "${NUL}${NUL}${SOH}µ"
473: "${NUL}${NUL}${SOH}Ù"
659: "${NUL}${NUL}${STX}${undef93}"

Since you want part of the string sorted numerically and part of the string sorted lexically (using the locale), you'll have to limit yourself to the ST.

@arr = map{ $_->[0] } sort { $a->[1] <=> $b->[1] || $a->[2] cmp $b->[2] } map{ [ $_, substr( $_, 1 ), substr( $_, 0, 1 ) ] } qw[ A473 B437 B659 C659 C123 D123 D222 E222 E001 A001 ];

In reply to Re: Sorting (GRT) and locale issues by ikegami
in thread 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.