Difference in perl sort order on Linux and Solaris, even when using locale.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Difference in perl sort order on Linux and Solaris, even when using locale.
Hello,
I'm hoping someone can help me out with an issue regarding perl sort. I'm facing a difference in the sort order between Solaris and Linux. I was hoping I could avoid this by using locale, but unfortunately, things still go wrong when special characters are used.
Using the code below:
Code:
#!/usr/bin/perl
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";
}
On both systems I'm using the same locale settings, though I must say, Linux seems to have some extra, for which I can't really believe they would be of influence on this. (Just to make sure, I tried to unset them, but their value remains POSIX)
I've tried using various settings of these, and I can see there's sometimes effect on the sort order, but always, Linux will prefer numbers over special characters, no matter what I try.
Can someone please help me out and provide a solution, so that the sort-order on both Linux and Solaris is the same?
Have you set these locale variables in the beginning of the perl script to make sure they are not being reset somewhere between your shell prompt and the call to sort() ?
Code:
%ENV=();
$ENV{"LC_MESSAGES"}="C";
...
other locale and PATH settings here
...
Last edited by linosaurusroot; 03-03-2014 at 08:43 AM.
Have you set these locale variables in the beginning of the perl script to make sure they are not being reset somewhere between your shell prompt and the call to sort() ?
Code:
%ENV=();
$ENV{"LC_MESSAGES"}="C";
...
other locale and PATH settings here
...
Hi Linosaurusroot,
Thanks for the tip. However, I'm afraid it didn't do the trick for me. I've added the lines below to the beginning of the script, but the results remain the same I'm afraid.
I almost always use "C" as the locale, and I rarely run into trouble.
Code:
NOTE: Not all systems have the "POSIX" locale (not all systems are
POSIX-conformant), so use "C" when you need explicitly to specify this
default locale.
from man perllocale
Here are sample runs from Debian GNU/Linux and Solaris:
I almost always use "C" as the locale, and I rarely run into trouble.
Code:
NOTE: Not all systems have the "POSIX" locale (not all systems are
POSIX-conformant), so use "C" when you need explicitly to specify this
default locale.
from man perllocale
Here are sample runs from Debian GNU/Linux and Solaris:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.