in reply to Sorting according to locale collation

'locale' is almost entirely dependent on the underlying OS, and then further on the libs and installed modules. Have a look on your perllocale manual to check how to tackle.

I think you might do 2 things to go on:

1) Check what locale settings are installed/available to you in the working environment (perllocale suggests a number of ways to do that)

2) Once you made sure the locale you want to use is available, go ahead with your code, but always do check also that the setting was successfull:
... my $loc = setlocale( LC_ALL, 'lt'); die 'Could not switch to locale "lt"!' if $loc ne 'lt'; ....

Replies are listed 'Best First'.
Re^2: Sorting according to locale collation
by amir_e_a (Hermit) on Apr 22, 2007 at 13:07 UTC
    Check what locale settings are installed/available to you in the working environment (perllocale suggests a number of ways to do that)

    I tried `locale -a' on Linux, and found out that it doesn't have 'lt', but it does have lt_LT, which should be the same. (It also has 'lithuanian' ... Is it a standard in Unix or some GNU extension?)

    Anyway, i tried running this:

    use strict; use warnings; use locale; use POSIX; my $loc = setlocale(LC_ALL, 'lt'); if (defined $loc) { print "loc is defined\n"; print "loc value: *$loc*\n"; } else { print "loc is undefined\n"; } my @sorttest = qw(ia ib ic ya yb yc); for (sort @sorttest) { print "$_\n"; }

    When i try 'lt_LT', $loc is 'lt_LT'. When i try 'lt', $loc is undefined, so i must be in the right direction.

    However, the sorting still doesn't work as i would expect Can it really be a bug in Linux?

    Also, perllocale suggests only Unix'ish ways to list available locales. Is there anything like `locale -a' on Windows? I'm trying to be portable.