Reputation: 69
I'm having issues sorting in Perl having different results in Windows and Unix.
The characters are: a - _ 1 2
In Windows: _ 1 2 - a
In Unix: _ - 1 2 a
I'm guessing the locale has something to do with this - what can I do to make the Unix sort match the Windows sort?
Thanks!
Upvotes: 1
Views: 495
Reputation: 241918
If you do not want to use locale, comment out the line containing
use locale;
Without such a line, sort
in Perl should behave the same on both Windows and Unix.
You can also add
no locale;
before the sort
(or, better, enclose the sort into a block starting with it).
Upvotes: 0
Reputation: 385897
The docs say:
*** WARNING *** The locale specified by the environment affects sort order. Set LC_ALL=C to get the traditional sort order that uses native byte values.
so use
LC_ALL=C sort ...
Example:
$ perl -E'say for @ARGV' a - _ 1 2 | LC_ALL=en_US.UTF-8 sort
_
-
1
2
a
$ perl -E'say for @ARGV' a - _ 1 2 | LC_ALL=C sort
-
1
2
_
a
Upvotes: 2