Mailing List Archive

setlocale vs LC_CTYPE
This was reported by Oleg Bartunov (Cc'd). Is this a bug that you have to
call setlocale explicitly? I thought $LC_CTYPE would be honored...

--tom

Tom, I have a problem with using perl and koi8-r (russian encoding).
I tried
23:51[ra]:~/News>perl -e '$a="oh no, ÄÖÅ"; $u=uc($a); print "$u\n";'
OH NO, ÄÖÅ

It doesn't work for cyrillic characters, in spite of variable LC_CTYPE
defined as koi8-r.

23:53[ra]:~/News>perl -e 'use POSIX; setlocale(LC_CTYPE,"koi8-r");$a="oh no,
ÄÖÅ"; $u=uc($a); print "$u\n";'
OH NO, äöå

Now it works ! Do I have every time I need locale use POSIX.pm ?
It's so slow.

Some info about my system: Sun Sparc 10/51, Solaris 2.4, Perl 5.01m

Thanks for nice postings about Perl,

-- Oleg
_____________________________________________________________________________
Oleg Bartunov - researcher, hostmaster
Sternberg Astronomical Institute, Moscow University
(095)939-16-83, oleg@sai.msu.su, Moscow, Russia
-----------------------------------------------------------------------------
setlocale vs LC_CTYPE [ In reply to ]
Tom Christiansen writes:
> This was reported by Oleg Bartunov (Cc'd). Is this a bug that you have to
> call setlocale explicitly? I thought $LC_CTYPE would be honored...
>
> --tom
>
> Tom, I have a problem with using perl and koi8-r (russian encoding).
> I tried
> 23:51[ra]:~/News>perl -e '$a="oh no, DVE"; $u=uc($a); print "$u\n";'
> OH NO, DVE
>
> It doesn't work for cyrillic characters, in spite of variable LC_CTYPE
> defined as koi8-r.
>
> 23:53[ra]:~/News>perl -e 'use POSIX; setlocale(LC_CTYPE,"koi8-r");$a="oh no,
> DVE"; $u=uc($a); print "$u\n";'
> OH NO, dve
>
> Now it works ! Do I have every time I need locale use POSIX.pm ?
> It's so slow.

LC_CTYPE is not honored by default. Yes, it should.

#ifdef I_LOCALE
#include <locale.h>
#endif /* #ifdef I_LOCALE */

...

#ifdef LC_CTYPE
{
char * lc_ctype;
if (lc_ctype = getenv("LC_CTYPE")) {
if (setlocale(LC_CTYPE, lc_ctype))
}
}
#endif

somewhere in the main() would be nice. (Yes, setlocale() very much
better be in main()).

Andy, maybe you could sneak in at least I_LOCALE into perl 5.001o?

++jhi;
Re: setlocale vs LC_CTYPE [ In reply to ]
: This was reported by Oleg Bartunov (Cc'd). Is this a bug that you have to
: call setlocale explicitly? I thought $LC_CTYPE would be honored...
:
: --tom

I think you at least have to do setlocale(LC_CTYPE, "").

: Tom, I have a problem with using perl and koi8-r (russian encoding).
: I tried
: 23:51[ra]:~/News>perl -e '$a="oh no, ÄÖÅ"; $u=uc($a); print "$u\n";'
: OH NO, ÄÖÅ
:
: It doesn't work for cyrillic characters, in spite of variable LC_CTYPE
: defined as koi8-r.
:
: 23:53[ra]:~/News>perl -e 'use POSIX; setlocale(LC_CTYPE,"koi8-r");$a="oh no,
: ÄÖÅ"; $u=uc($a); print "$u\n";'
: OH NO, äöå
:
: Now it works ! Do I have every time I need locale use POSIX.pm ?
: It's so slow.

You can speed it up considerably by saying

use POSIX 'setlocale';

Larry
Re: setlocale vs LC_CTYPE [ In reply to ]
On Wed, 1 Nov 1995, Larry Wall wrote:

> : This was reported by Oleg Bartunov (Cc'd). Is this a bug that you have to
> : call setlocale explicitly? I thought $LC_CTYPE would be honored...
> :
> : --tom
>
> I think you at least have to do setlocale(LC_CTYPE, "").
>
> : Tom, I have a problem with using perl and koi8-r (russian encoding).
> : I tried
> : 23:51[ra]:~/News>perl -e '$a="oh no, ÄÖÅ"; $u=uc($a); print "$u\n";'
> : OH NO, ÄÖÅ
> :
> : It doesn't work for cyrillic characters, in spite of variable LC_CTYPE
> : defined as koi8-r.
> :
> : 23:53[ra]:~/News>perl -e 'use POSIX; setlocale(LC_CTYPE,"koi8-r");$a="oh no,
> : ÄÖÅ"; $u=uc($a); print "$u\n";'
> : OH NO, äöå
> :
> : Now it works ! Do I have every time I need locale use POSIX.pm ?
> : It's so slow.
>
> You can speed it up considerably by saying
>
> use POSIX 'setlocale';
>
> Larry
>
Yes, it works, but still slow. Certainly we need locale support built-in...

Best regards,
Oleg Bartunov



_____________________________________________________________________________
Oleg Bartunov - researcher, hostmaster
Sternberg Astronomical Institute, Moscow University
(095)939-16-83, oleg@sai.msu.su, Moscow, Russia
-----------------------------------------------------------------------------
Re: setlocale vs LC_CTYPE [ In reply to ]
: Yes, it works, but still slow. Certainly we need locale support built-in.=

Yes, I can see where you wouldn't get very far in Russian without it.
I will do the patch (or something like the patch) that was posted here.

Larry