develooper Front page | perl.perl5.porters | Postings from December 2004

Perl setlocale?

Thread Next
From:
Glenn Linderman
Date:
December 30, 2004 20:38
Subject:
Perl setlocale?
Message ID:
41D4D7BD.1060408@nevcal.com
The following message has gone unanswered on ActiveState's Win32 perl 
user's group.  Of course, maybe it is the holidays.  But I wondered if 
maybe a Windows porter could point me in the right direction to figure 
this out.  The documentation for setlocale is quite generic, and could 
probably be improved, at least for Windows users.  And from what I've 
encountered so far, maybe there are also bugs in the code, as I get 
screwy errors, unchanged locale information, and inability to change to 
a new code page.

Here are the details:


So, I'm experimenting with trying to change code pages.  Although
Windows documents GetACP to discover the current code page, there is no
corresponding SetACP...

Finally discovered that Windows setlocale function is supposed to change
code pages... and that Perl wraps Windows setlocale... but

1) The default code page is 437.  When I call setlocale with no
parameters, it reports "English_United States.1252".

2) I change the code page to 65001 (UTF-8, supposedly).  I get the same
report from setlocale.

3) I try calling setlocale with "English_United States.65001" and it
gives me an error, that says "strxfrm() gets absurd", which is,
admittedly, an absurd error, but it is not clear what is absurd about
the string such that strxfrm shouldn't like it... even if the string
isn't in the proper format.

4) I try calling setlocale with "en_us.65001", and various other
capitalizations that I see floating around the web, and no errors are
reported.... but neither does the output of a parameterless setlocale
call change from the "English_United States.1252".

Windows 2000, if it matters.  Version 5.00.2195 and autoupdate turned on.

Here's some code.  Supply as the first argument the locale string under
test.

use strict;
use warnings;
use locale;
use POSIX qw(locale_h);
my $debug = 1;
my ( $locale, $oldlocale, $midlocale, $newlocale );
print Win32::FormatMessage( Win32::GetLastError())  if $debug;
$locale = $ARGV[ 0 ];
$locale = 'English_United States.65001'  unless defined $ARGV[ 0 ];
$oldlocale = POSIX::setlocale( POSIX::LC_ALL());
print Win32::FormatMessage( Win32::GetLastError())  if $debug;
print $oldlocale . "\n"  if $debug;
$midlocale = POSIX::setlocale( POSIX::LC_ALL(), $locale);
print Win32::FormatMessage( Win32::GetLastError())  if $debug;
$newlocale = POSIX::setlocale( POSIX::LC_ALL());
print Win32::FormatMessage( Win32::GetLastError())  if $debug;
print $newlocale . "\n"  if $debug  &&  $newlocale ne $oldlocale;



-- 
Glenn -- http://nevcal.com/
===========================
Having identified a vast realm of ignorance, Wolfram is saying that much
of this realm lies forever outside the light cone of human knowledge.
                           -- Michael Swaine, Dr Dobbs Journal, Sept 2002

Thread Next


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