Hi,

I am a teacher on a Danish Technical High School, and had a Perl Network Management Course this week. On of the students submitted a question that we solved, but I could not explain it.

My student was sorting words, but sort() got it all wrong. I discovered that he used use locale; which I know can give problems. We solved his problem, but I could not explain what happened.

Environment: ActiveState Perl 5.8.8 build 822 (MSWin32-x86-multi-thread) on Danish XP-pro. The following sample code fails on Windows but not on FreeBSD, Solaris or RedHat. Also tried ActiveState 5.10.0 on XP, which failed as well.

use strict; use warnings; my @a = qw(a b c d e f g h i j k l A B C D E F G H I J K L); my @b = qw(aaa aab aba abb Laa lab); no locale; print "no locale : "; print sort(@a),"\n"; use POSIX; print "POSIX : "; print sort(@a),"\n"; use locale;print "use locale: "; print sort(@a),"\n"; no locale; print "no locale : "; foreach (sort(@b)){printf "%-4s", $_;} print "\n"; use POSIX; print "POSIX : "; foreach (sort(@b)){printf "%-4s", $_;} print "\n"; use locale;print "use locale: "; foreach (sort(@b)){printf "%-4s", $_;}

This code produces the following output on XP:

no locale : ABCDEFGHIJKLabcdefghijkl POSIX : ABCDEFGHIJKLabcdefghijkl use locale: aAbBcCdDeEfFgGhHiIjJkKlL no locale : Laa aaa aab aba abb lab POSIX : Laa aaa aab aba abb lab use locale: aba abb lab Laa aaa aab

Does anybody know why the sort with use locale produces aba abb lab Laa aaa aab.

Best regards

Henrik Thomsen


In reply to use locale; on ActiveState WIN32 by heth

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.