This was _really_ annoying me to the point of burning effigies of
camels, so with a view to helping any other unwary souls -
Problem:
After rolling your own installation of perl , when you try to run a perl
script you get a variation on the following:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LC_ALL = "En_US",
LANG = (unset)
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Several places on the internet, including the ADC section of the apple
web site, suggest creating a .tcshrc or .bash file containing the
missing variables. This is only a partial solution however, working only
if you run the script from a terminal window (aka CLI) - perl scripts
run as standalones, cron jobs and so on, still throw up locale errors
because the system environment doesn't have the necessary variable(s) set
The solution?
I got the answer thanks to this page by Bob Dalgleish
http://duke.usask.ca/~dalglb/macosx/Perl_5.6.html
where it gives an example of a shell script which makes an
environment.plist containing the missing locale variable(s).
I've turned it into a perl script (written for clarity rather than
compactness) with some extra features which I think might be useful
(like the ability to change the language locale).
==SCRIPT STARTS BELOW THIS TEXT==
#!/usr/bin/perl -w
# Locale WTK(water torture killer).pl
# Author Robin McFarlane <[EMAIL PROTECTED]>
#
# based on the shell script written by by Bob Dalgleish
# viewable at http://duke.usask.ca/~dalglb/macosx/Perl_5.6.html
#
# This script will look for any missing folders and files in your user
folder,
# needed to kill locale related errors, creating them as need be.
#
# It will also safely add missing locale info to an existing
environment.plist,
# making a back-up of the original called "environment.plist.old" in the
same folder.
#=========== declare includes =============
use strict;
use diagnostics-verbose;
#========== declare variables =============
my ($TempPath,$path,$flag,$dir,$Missing1,$Missing2);
my (@NewPlist,@OldPlist,@Template,$TempFile,$plist);
my (%DataCheck,$ChangeFlag);
$path=join ('/', '/Users',$ENV{USER});
$dir ='.MacOSX';
$plist='environment.plist';
@Template=<DATA>;
print "Checking your current environment set up\n";
$TempPath= join ('/',$path,$dir);
if (-e $TempPath){
print "\t",$TempPath," exists\n";
}else{
print "\t",$TempPath," is missing - creating it now\n";
mkdir $TempPath || die "can't make $TempPath,\n OS says $!";
}
$TempPath= join ('/',$TempPath,$plist);
if (-f $TempPath){
print "\t",$TempPath," exists, checking the locale data\n";
open(IN, $TempPath)|| die "can't open $TempPath,\n OS says $!";
@OldPlist=<IN>;
close (IN);
@DataCheck{@OldPlist}=();
for (@Template){
unless (exists $DataCheck{$_}){
print "\t$_ missing from $TempPath, adding\n";
$DataCheck{$_}=() ;
$ChangeFlag=1;
}
@NewPlist=keys(%DataCheck);
if ($ChangeFlag){
$flag = rename $TempPath,$TempPath.'.old';
die "can't seem to modify $TempFile, may be permissions
related\n" if $flag;
}
}
} else {
print "\t",$TempPath," is missing - creating it now\n";
@NewPlist=@Template;
$ChangeFlag=1;
}
if ($ChangeFlag){
open (OUT,">$TempPath") || die "can't print to $TempPath,\n OS
says $!";
print OUT @NewPlist;
close (OUT);
print "your locale data has been updated - \nany changes will come
into effect the next time you log into OSX. \n";
}else { print "No data was changed, any problems you might be
experiencing \nare not connected with your environment.plist\n"; }
__DATA__
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM
"file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>LANG</key>
<string>us_ENG</string>
<key>LC_ALL</key>
<string>C</string>
</dict>
</plist>
==SCRIPT STARTS ABOVE THIS TEXT==