develooper Front page | perl.perl5.porters | Postings from October 2003

Use locale doesn't work as documented on Windows? [was: Re: require patch breaks locale]

Thread Previous
From:
Steve Hay
Date:
October 7, 2003 05:17
Subject:
Use locale doesn't work as documented on Windows? [was: Re: require patch breaks locale]
Message ID:
3F82AF35.6070602@uk.radan.com
H.Merijn Brand wrote:

>Latest smoke on my linux shows breackage along the line for require:
>
>   21415     Configuration (common) none
>------------ ----------------------------------------------------------------
>O O F O O F
>O O F O O F  -Duse64bitint
>O O F O O F  -Duselongdouble
>O O F O O F  -Dusemorebits
>O O F O O F  -Duseithreads
>O O F O O F  -Duseithreads -Duse64bitint
>O O F O O F  -Duseithreads -Duselongdouble
>O O F O O F  -Duseithreads -Dusemorebits
>O O F O O F  -Accflags='-DPERL_COPY_ON_WRITE'
>O O F O O F  -Accflags='-DPERL_COPY_ON_WRITE' -Duse64bitint
>O O F O O F  -Accflags='-DPERL_COPY_ON_WRITE' -Duselongdouble
>O O F O O F  -Accflags='-DPERL_COPY_ON_WRITE' -Dusemorebits
>O O F O O F  -Accflags='-DPERL_COPY_ON_WRITE' -Duseithreads
>O O F O O F  -Accflags='-DPERL_COPY_ON_WRITE' -Duseithreads -Duse64bitint
>O O F O O F  -Accflags='-DPERL_COPY_ON_WRITE' -Duseithreads
>                (cont) -Duselongdouble
>O O F O O F  -Accflags='-DPERL_COPY_ON_WRITE' -Duseithreads -Dusemorebits
>| | | | | +- LC_ALL = en_US.utf8 -DDEBUGGING
>| | | | +--- PERLIO = perlio -DDEBUGGING
>| | | +----- PERLIO = stdio  -DDEBUGGING
>| | +------- LC_ALL = en_US.utf8
>| +--------- PERLIO = perlio
>+----------- PERLIO = stdio
>  
>
I can't even get the locale thing working properly on my Windows machine.

The setlocale() function works OK, so with no LC environment variables 
set I get:

    >perl -MPOSIX -e "print strftime('%#x', localtime)"
    07 October 2003
    >perl -MPOSIX -e "setlocale(LC_ALL, 'German'); print strftime('%#x', 
localtime)"
    Dienstag, 7. Oktober 2003

but "use locale;" doesn't seem to work.  If I now "set LC_ALL=German" 
then I still get:

    >perl -Mlocale -MPOSIX -e "print strftime('%#x', localtime)"
    07 October 2003

I also get no warnings if LC_ALL is set to some garbage value like "FooBar".

Is it supposed to work on Windows?  There's no mention that it doesn't, 
either in perlport or in perllocale.

It seems that in the absence of any setlocale() override, the text 
produced by POSIX::strftime(), at least, is actually controlled by the 
"Regional and Language Options" ("Start -> Settings -> Control Panel -> 
Regional and Language Options -> Regional Options -> Standards and 
formats" on my WinXP machine) rather than any environment variables, and 
that this Control Panel option actually takes effect whether or not one 
specifies "use locale;" in the Perl script!

So, with that option set to "German (Germany)" I now get:

    >perl -Mlocale -MPOSIX -e "print strftime('%#x', localtime)"
    Dienstag, 7. Oktober 2003

and even:

    >perl -MPOSIX -e "print strftime('%#x', localtime)"
    Dienstag, 7. Oktober 2003

whatever LC_* environment variables are set.

Is this the way it is supposed to work?  I have no objection to the 
Control Panel option being used (although it would also be nice to have 
the environment variables take precedence if they are present, much like 
setlocale() takes precedence over the environment, since they are more 
easily changed non-interactively), but should it be used when "use 
locale;" has not been specified?  perllocale says "By default, Perl 
ignores the current locale. The use locale pragma tells Perl to use the 
current locale for some operations."  This is clearly not true on 
Windows, so either Perl or perllocale needs fixing.

The use of the Control Panel option should also be mentioned somewhere, 
and likewise the non-use of the LC_* environment variables.

I could provide some doc patches if it just the docs that need changing.

- Steve


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About