How to reset LC_TIME in time

--Sig_//h9P8rhq0.vP29Wqy.F6Do8
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable

I got a report from someone using one of my scripts that it started
being very noisy when they changed their LC_TIME to something that was
not showing up under 'locale -a'. Demo:

$ env LC_TIME=3Den_US.UTF-8 perl -wE'say 1'
1

$ env LC_TIME=3Den_US.UTF-9 perl -wE'say 1'
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE =3D (unset),
        LC_ALL =3D (unset),
        LC_CTYPE =3D "en_US.UTF-8",
        LC_TIME =3D "en_US.UTF-9",
        LANG =3D "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
1

So I suggested a BEGIN block but to no avail:

$ env LC_TIME=3Den_US.UTF-9 perl -wE'BEGIN{$ENV{LC_TIME}=3D"en_US.UTF-8"} s=
ay 1'
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE =3D (unset),
        LC_ALL =3D (unset),
        LC_CTYPE =3D "en_US.UTF-8",
        LC_TIME =3D "en_US.UTF-9",
        LANG =3D "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
1

same for CHECK and INIT

Is there a way to timely reset LC_TIME inside a perl script *before*
I get that noise?

--=20
H.Merijn Brand  http://tux.nl   Perl Monger  http://amsterdam.pm.org/
using perl5.00307 .. 5.29   porting perl5 on HP-UX, AIX, and openSUSE
http://mirrors.develooper.com/hpux/        http://www.test-smoke.org/
http://qa.perl.org   http://www.goldmark.org/jeff/stupid-disclaimers/

--Sig_//h9P8rhq0.vP29Wqy.F6Do8
Content-Type: application/pgp-signature
Content-Description: OpenPGP digital signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBAgAGBQJb2GbxAAoJEAOhR6E+XcCYaSoIAJW1TpwRWd1sTKFTBEJWJh6J
moS0dkWgrfvBSgr2+EQ/kc5BU0jpnr0ge2Hw3TtjiTWFVNrdXAUOaZApXckb2vXo
QBdE/uqH7WhfUd1Bmd6Y3+OEnA2rOtX3g/s6vSKbwkpCc6wUqzwngRUbKM7BjmYa
YGlV5Tv8Dw1/fpLukihMsAIYH/1NVYnZATsKOV0iEGseTYhNOBZLkRzdtd+x315T
1P+Qh1NOy6fltw03YeHsWfK37kh6He9adaSq/14gj8pwk4i3LbP3AuCAt+RO6Pcy
e1WhxXV9bHHukV7V4TDEFdqK3daAjL8jFT58+vHeGj25am/ERJNAuEqrB+ikc5s=
=C2dF
-----END PGP SIGNATURE-----

--Sig_//h9P8rhq0.vP29Wqy.F6Do8--
0
h
10/30/2018 2:12:56 PM
perl.perl5.porters 47403 articles. 0 followers. Follow

3 Replies
13 Views

Similar Articles

[PageSpeed] 54

On 10/30/18 8:12 AM, H.Merijn Brand wrote:
> I got a report from someone using one of my scripts that it started
> being very noisy when they changed their LC_TIME to something that was
> not showing up under 'locale -a'. Demo:
> 
> $ env LC_TIME=en_US.UTF-8 perl -wE'say 1'
> 1
> 
> $ env LC_TIME=en_US.UTF-9 perl -wE'say 1'
> perl: warning: Setting locale failed.
> perl: warning: Please check that your locale settings:
>          LANGUAGE = (unset),
>          LC_ALL = (unset),
>          LC_CTYPE = "en_US.UTF-8",
>          LC_TIME = "en_US.UTF-9",
>          LANG = "en_US.UTF-8"
>      are supported and installed on your system.
> perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
> 1
> 
> So I suggested a BEGIN block but to no avail:
> 
> $ env LC_TIME=en_US.UTF-9 perl -wE'BEGIN{$ENV{LC_TIME}="en_US.UTF-8"} say 1'
> perl: warning: Setting locale failed.
> perl: warning: Please check that your locale settings:
>          LANGUAGE = (unset),
>          LC_ALL = (unset),
>          LC_CTYPE = "en_US.UTF-8",
>          LC_TIME = "en_US.UTF-9",
>          LANG = "en_US.UTF-8"
>      are supported and installed on your system.
> perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
> 1
> 
> same for CHECK and INIT
> 
> Is there a way to timely reset LC_TIME inside a perl script *before*
> I get that noise?
> 

No.

The locale is considered so basic that it is close to the very first 
thing dealt with at startup of the script, long before any Perl 
statement is executed.

You can, however, keep this message from being raised.  See PERL_BADLANG 
in perllocale
0
public
10/30/2018 2:33:04 PM
--Sig_/ETwF_/ZAohrLY/Z44dA4pzt
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable

On Tue, 30 Oct 2018 08:33:04 -0600, Karl Williamson
<public@khwilliamson.com> wrote:

> On 10/30/18 8:12 AM, H.Merijn Brand wrote:
> > I got a report from someone using one of my scripts that it started
> > being very noisy when they changed their LC_TIME to something that was
> > not showing up under 'locale -a'. Demo:
> >=20
> > $ env LC_TIME=3Den_US.UTF-8 perl -wE'say 1'
> > 1
> >=20
> > $ env LC_TIME=3Den_US.UTF-9 perl -wE'say 1'
> > perl: warning: Setting locale failed.
> > perl: warning: Please check that your locale settings:
> >          LANGUAGE =3D (unset),
> >          LC_ALL =3D (unset),
> >          LC_CTYPE =3D "en_US.UTF-8",
> >          LC_TIME =3D "en_US.UTF-9",
> >          LANG =3D "en_US.UTF-8"
> >      are supported and installed on your system.
> > perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
> > 1
> >=20
> > So I suggested a BEGIN block but to no avail:
> >=20
> > $ env LC_TIME=3Den_US.UTF-9 perl -wE'BEGIN{$ENV{LC_TIME}=3D"en_US.UTF-8=
"} say 1'
> > perl: warning: Setting locale failed.
> > perl: warning: Please check that your locale settings:
> >          LANGUAGE =3D (unset),
> >          LC_ALL =3D (unset),
> >          LC_CTYPE =3D "en_US.UTF-8",
> >          LC_TIME =3D "en_US.UTF-9",
> >          LANG =3D "en_US.UTF-8"
> >      are supported and installed on your system.
> > perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
> > 1
> >=20
> > same for CHECK and INIT
> >=20
> > Is there a way to timely reset LC_TIME inside a perl script *before*
> > I get that noise?
> >  =20
>=20
> No.
>=20
> The locale is considered so basic that it is close to the very first=20
> thing dealt with at startup of the script, long before any Perl=20
> statement is executed.
>=20
> You can, however, keep this message from being raised.  See PERL_BADLANG=
=20
> in perllocale

Yeah, but as you cannot do that in a BEGIN/CHECK/INIT, as that is too
late anyway, I will have to write a wrapper (or I have the person with
the problem do that) and then I can just as easy set a correct LC_TIME
in the wrapper instead of setting PERL_BADLANG

--=20
H.Merijn Brand  http://tux.nl   Perl Monger  http://amsterdam.pm.org/
using perl5.00307 .. 5.29   porting perl5 on HP-UX, AIX, and openSUSE
http://mirrors.develooper.com/hpux/        http://www.test-smoke.org/
http://qa.perl.org   http://www.goldmark.org/jeff/stupid-disclaimers/

--Sig_/ETwF_/ZAohrLY/Z44dA4pzt
Content-Type: application/pgp-signature
Content-Description: OpenPGP digital signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBAgAGBQJb2G65AAoJEAOhR6E+XcCYeDwH/RWXO2YCLxV7vd9ALPBtQpwK
L7ekZcuYJt1QcUaoMm4JtR7eY45am8dik7ezZrse7YN3HlRPN2cexzw6hNo6Jo7+
deMVV6urNCLtEiVs2tDEz7UGjywOslqXjj5S7JHSHlwBkRR++pHjaWJ7Ufy05gc+
uHUFX0cP/AgYLdPrk/OnIaMwMgBNRNiO1K5ozP7VxdF5FBEM1ix1h2FqBN6WeD1c
LiEXJJRpNL10TmvUfdD6KuQ3KaemED6rqHsH7oUnEbovu6XixlrTEvl7ZtU6IV6F
wwT09vvC9Rn6zeo5weLexS4HejUHJO+vDa0dUWc8w0kvnA86dSVWdmvx+8M+dao=
=MCa9
-----END PGP SIGNATURE-----

--Sig_/ETwF_/ZAohrLY/Z44dA4pzt--
0
h
10/30/2018 2:46:08 PM
On 10/30/18 10:12 AM, H.Merijn Brand wrote:
> I got a report from someone using one of my scripts that it started
> being very noisy when they changed their LC_TIME to something that was
> not showing up under 'locale -a'. Demo:
> 
> $ env LC_TIME=en_US.UTF-8 perl -wE'say 1'
> 1
> 
> $ env LC_TIME=en_US.UTF-9 perl -wE'say 1'
> perl: warning: Setting locale failed.
> perl: warning: Please check that your locale settings:
>          LANGUAGE = (unset),
>          LC_ALL = (unset),
>          LC_CTYPE = "en_US.UTF-8",
>          LC_TIME = "en_US.UTF-9",
>          LANG = "en_US.UTF-8"
>      are supported and installed on your system.
> perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
> 1
> 
> So I suggested a BEGIN block but to no avail:
> 
> $ env LC_TIME=en_US.UTF-9 perl -wE'BEGIN{$ENV{LC_TIME}="en_US.UTF-8"} say 1'
> perl: warning: Setting locale failed.
> perl: warning: Please check that your locale settings:
>          LANGUAGE = (unset),
>          LC_ALL = (unset),
>          LC_CTYPE = "en_US.UTF-8",
>          LC_TIME = "en_US.UTF-9",
>          LANG = "en_US.UTF-8"
>      are supported and installed on your system.
> perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
> 1
> 
> same for CHECK and INIT
> 
> Is there a way to timely reset LC_TIME inside a perl script *before*
> I get that noise?
> 

I suspect not, given where that warning is being generated in locale.c:

#####

3086 /*
3087  * Initialize locale awareness.
3088  */
3089 int
3090 Perl_init_i18nl10n(pTHX_ int printwarn)
3091 {
....
3464             if (locwarn) { /* Output failure info only on the first 
one */
3465
3466 #  ifdef LC_ALL
3467
3468                 PerlIO_printf(Perl_error_log,
3469                 "perl: warning: Setting locale failed.\n");
3470
3471 #  else /* !LC_ALL */
3472
3473                 PerlIO_printf(Perl_error_log,
3474                 "perl: warning: Setting locale failed for the 
categories:\n\t");
3475
3476                 for (j = 0; j < NOMINAL_LC_ALL_INDEX; j++) {
3477                     if (! curlocales[j]) {
3478                         PerlIO_printf(Perl_error_log, 
category_names[j]);
3479                     }
3480                     else {
3481                         Safefree(curlocales[j]);
3482                     }
3483                 }
3484
3485 #  endif /* LC_ALL */
3486
3487                 PerlIO_printf(Perl_error_log,
3488                     "perl: warning: Please check that your locale 
settings:\n");
3489
3490 #  ifdef __GLIBC__
3491
3492                 PerlIO_printf(Perl_error_log,
3493                             "\tLANGUAGE = %c%s%c,\n",
3494                             language ? '"' : '(',
3495                             language ? language : "unset",
3496                             language ? '"' : ')');
3497 #  endif
3498
3499                 PerlIO_printf(Perl_error_log,
3500                             "\tLC_ALL = %c%s%c,\n",
3501                             lc_all ? '"' : '(',
3502                             lc_all ? lc_all : "unset",
3503                             lc_all ? '"' : ')');
3504
3505 #  if defined(USE_ENVIRON_ARRAY)
3506
3507                 {
3508                     char **e;
3509
3510                     /* Look through the environment for any 
variables of the
3511                      * form qr/ ^ LC_ [A-Z]+ = /x, except LC_ALL 
which was
3512                      * already handled above.  These are assumed to 
be locale
3513                      * settings.  Output them and their values. */
3514                     for (e = environ; *e; e++) {
3515                         const STRLEN prefix_len = sizeof("LC_") - 1;
3516                         STRLEN uppers_len;
3517
3518                         if (     strBEGINs(*e, "LC_")
3519                             && ! strBEGINs(*e, "LC_ALL=")
3520                             && (uppers_len = strspn(*e + prefix_len,
3521 
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
3522                             && ((*e)[prefix_len + uppers_len] == '='))
3523                         {
3524                             PerlIO_printf(Perl_error_log, "\t%.*s = 
\"%s\",\n",
3525                                 (int) (prefix_len + uppers_len), *e,
3526                                 *e + prefix_len + uppers_len + 1);
3527                         }
3528                     }
3529                 }
3530
3531 #  else
3532
3533                 PerlIO_printf(Perl_error_log,
3534                             "\t(possibly more locale environment 
variables)\n");
3535
3536 #  endif
3537
3538                 PerlIO_printf(Perl_error_log,
3539                             "\tLANG = %c%s%c\n",
3540                             lang ? '"' : '(',
3541                             lang ? lang : "unset",
3542                             lang ? '"' : ')');
3543
3544                 PerlIO_printf(Perl_error_log,
3545                             "    are supported and installed on 
your system.\n");
3546             }
#####

That's what you'd have to work around.
0
jkeenan
10/30/2018 3:26:34 PM
Reply: