Following data needs to be sorted respecting the locale sort order:
wird
sin
wär
pêche
war
Über
Uber
péché
peach
There was nor problem by using sort
$ sort < data
peach
pêche
péché
sin
Uber
Über
war
wär
wird
which respects the locale, and
$ LC_ALL=C sort < data
Uber
peach
péché
pêche
sin
war
wird
wär
Über
without locale.
Now I tried to do so with perl
, but I'm failed:
$ perl -e 'local $/ = undef; print sort <>;' < data
Über
pêche
war
péché
sin
Uber
peach
wär
wird
The result is either the first output of sort, nor the second.
Running Ubuntu 12.04 LTS
Best Answer
The problem is
local $/ = undef
. It causesperl
to read entire file in to@ARGV
array, meaning it contains only one element, sosort
can not sort it (because you are sorting an array with only one element). I expect the output must be the same with your beginning data (I also useUbuntu 12.04 LTS, perl version 5.14.2
:If you remove
local $/ = undef
, perlsort
will proceduce same output with the shellsort with LC_ALL=C
:Note
Without
use locale
,perl
ignores your current locale settings. Perl comparison operators("lt", "le", "cmp", "ge", and "gt")
useLC_COLLATE
(whenLC_ALL
absented), andsort
is also effected because it usecmp
by default.You can get current
LC_COLLATE
value: