in reply to Difference in sort order between Solaris and Linux

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.

Replies are listed 'Best First'.
Re^2: Difference in sort order between Solaris and Linux
by lpwevers (Acolyte) on Mar 06, 2014 at 09:30 UTC
    Hi Laurent

    Thanks for the explanation. I've tested this and found that indeed the output is the same on both Solaris and Linux. So instead of using the Perl sort function I'll use the Schwartzian Transform as you suggested.

    Kind Regards,
    Louis