OpenVZ Forum


Home » General » Support » setlocale not working properly in perl script
setlocale not working properly in perl script [message #31005] Thu, 12 June 2008 14:21
TowerGuard is currently offline  TowerGuard
Messages: 1
Registered: June 2008
Location: Westchester, NY
Junior Member
I've encountered an issue in my perl script where the locale of the box I'm running on affects the length() calculation of strings with multibyte characters. The current locale setting of the box is en_US.UTF-8. If I "export LC_CTYPE=en_US" at the UNIX prompt and then run the script, the length() function does what I want it to. However, I want the script to set the locale dynamically. I found the follwing code from various sites online but none of them seem to have the effect that they should. For instance I use:

use locale;
use POSIX qw(locale_h);
$oldlocale = setlocale(LC_CTYPE);
$newlocale = setlocale(LC_CTYPE, "en_US");

The setlocale function seems to set the locale correctly as when I print $oldlocale and $newlocale I get en_US.UTF-8 and en_US respectively.

However my length function still treats the multibyte characters in an undesired way.

How come when I change the locale at the UNIX prompt it works as desired but when I change it in the script, it does not?

Thanks,
Steve
 
Read Message
Previous Topic: how to open a range of IPs?
Next Topic: HN Network Connectivity loss when VE stopped
Goto Forum:
  


Current Time: Wed Nov 06 00:46:18 GMT 2024

Total time taken to generate the page: 0.03473 seconds