2

Related to this question but more in-depth. I am running a command like the following:

foreach $dir (@dirs) {
    $cnt = `svn st $dir | wc -l`;
    if($cnt > 0){
        $content .= "$dir\n";
        $mods++;
    }
}

However the directory contains non-ASCII files and thus throws an error when the locale is incorrect or not set.

The correct way to set the locale I need in perl is

setlocale(LC_CTYPE, 'en_US.UTF-8');

However, this does not seem to be affecting the svn st command, as the locale error still occurs when the perl script is not run in a terminal with the correct locale set.

Community
  • 1
  • 1
Tom Ritter
  • 99,986
  • 30
  • 138
  • 174

2 Answers2

4

You need to set the environment variable for the external command:

$cnt = `LC_CTYPE=en_US.UTF-8 svn st $dir | wc -l`;

You could also change the environment of the script (%ENV), which changes the environment for any child processes:

$ENV{LC_CTYPE} = 'en_US.UTF-8';
Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
3

Setup the environment for new processes by manipulating the %ENV hash.

$ENV{LC_CTYPE} = 'en_US.UTF-8';
$cnt = `svn ...`;
mob
  • 117,087
  • 18
  • 149
  • 283