Hi, my understanding is that you don't really care how special characters are sorted out, provided they get sorted the same way on your two platforms. Based on this assumption, and continuing on my idea of preprocessing your data, I think that the following program (using option 1 of my previous post) should give you the same results on both platforms:
#!/usr/bin/perl use strict; use warnings; my @toSort = ('SortTest', 'TestSort', 'Sort_Test', 'Test_Sort', 'Test1_Sort', 'Sort1_Test', 'Sort_1Test', 'Test_1Sort'); my @sortedList = map {$_->[0]} sort {$a->[1] cmp $b->[1]} map { my $c= $_; $c =~ s/_//g; [$_, $c] } @toSort; print join "\n", @sortedList;
I believe that this program should give you the same following output on both platforms (but, of course, I can't test, it is up to you to try):
$ perl sort_files.pl Sort1_Test Sort_1Test SortTest Sort_Test Test1_Sort Test_1Sort TestSort Test_Sort
This program uses the principle of the Schwartzian Transform I mentioned in my earlier post. The main 3-line sorting command should be read from bottom to top to be understood. Basically, the map at the bottom transforms each element of the original array into a record (anonymous array) of 2 elements: the original value and a version of it without the '_' (something like ['Test_Sort', 'TestSort']). Then, the sort line sorts the records on the second element of each record (i.e. the filename without the _), and, finally, the top map extracts the original value from the sorted records. This will probably be very slightly slower than your sort program, but only by a small margin, you are unlikely to even notice the difference unless you input has dozens or hundreds of megabytes. please ask if you need further explanations.

In reply to Re: Difference in sort order between Solaris and Linux by Laurent_R
in thread 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.