pcouderc has asked for the wisdom of the Perl Monks concerning the following question:

I have script which prints date, something like (simplified here):
#!/usr/bin/perl # # use strict; require 5.004; `date > /var/www/developer/svnlog.txt`;
I use it under a linux console with : perl myscript.pl I get the date in FRENCH locale (as I expect it).
I have done a perl script which handles some TCP port and executes this script, with a  `perl myscript.pl` and then the locale is in ENGLISH.
My question is what changes betweene these 2 excutions and how can I control the locale (I want the french locale)?
Thank you in advance
Pierre Couderc

Replies are listed 'Best First'.
Re: which locale is used by perl interpretor?
by marto (Cardinal) on Oct 03, 2006 at 12:38 UTC
    Hi Pierre,

    You may want to read perldoc perllocale, which describes locale handling and the solution to your current problem.

    Hope this helps.

    Martin
Re: which locale is used by perl interpretor?
by borisz (Canon) on Oct 03, 2006 at 12:41 UTC
    Your environment is different somehow. see perldoc perllocale But I think you just want something like this:
    export LC_ALL=fr_FR date
    or your script.
    Boris
Re: which locale is used by perl interpretor?
by jasonk (Parson) on Oct 03, 2006 at 12:44 UTC

    This depends mostly on how you are running the server on a tcp port. When you run it from the command line you are getting the locale specified in your shell initialization file (.profile, .bashrc, etc depending which shell you are using). If you are running the server from inittab or from inetd or something similar, then you are getting the environment of whatever system user started the super-daemon. The easiest way to resolve it would be to add the appropriate environment variable to the top of the script (probably something like $ENV{LANG} = "fr_FR.UTF-8";)


    We're not surrounded, we're in a target-rich environment!
Re: which locale is used by perl interpretor?
by pcouderc (Monk) on Oct 09, 2006 at 05:46 UTC
    Thank you, o wise monks
    Yes it was perlocale, the doc I had missed.
    I added :
    setlocale(LC_ALL, "fr_FR");

    and associated code, and my probem vanished. I suppose the the environment of the handler is not in the same locale the the one under the console...
    Thank you
    Pierre Couderc