lpwevers has asked for the wisdom of the Perl Monks concerning the following question:
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.
Running this gives the output below:#!/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"; }
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
|
---|
Back to
Seekers of Perl Wisdom