Dear Perl Monks,
I'm faced with an issue with Perl in which you can hopefully assist me. I have a Perl program that needs to run on both Sun Solaris and RedHat Enterprise Linux 6. One of the things it needs to do is sort a list. However, on Solaris and Linux the sort order is different when it comes to special characters. I tried using locale settings to avoid this issue, but to no avail. Below is an example script and the output on both Linux and Solaris.

#!/usr/bin/perl $ENV{LANG} = 'en_US'; $ENV{LC_ALL} = 'en_US.ISO8859-1'; use strict; use warnings; use locale; my $i; my @sortedList; my @toSort = ('SortTest', 'TestSort', 'Sort_Test', 'Test_Sort', 'Test1_Sort', 'Sort1_Test', 'Sort_1Test', 'Test_1Sort'); @sortedList = sort (@toSort); for ($i = 0; $i <= $#sortedList; $i++) { print "$i:\t$sortedList[$i]\n"; }
Running this gives the output below:
Linux Solaris 0: Sort_1Test 0: Sort_1Test 1: Sort1_Test 1: Sort_Test 2: SortTest 2: Sort1_Test 3: Sort_Test 3: SortTest 4: Test_1Sort 4: Test_1Sort 5: Test1_Sort 5: Test_Sort 6: TestSort 6: Test1_Sort 7: Test_Sort 7: TestSort

As can be seen, Linux prefers numbers over special characters, while on Solaris it's the other way round.

The question of course is, how can I make both Linux and Solaris behave equal?

Many thanks in advance.
Louis

In reply to Difference in sort order between Solaris and Linux by lpwevers

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.