http://qs321.pair.com?node_id=637449

blahblahblah has asked for the wisdom of the Perl Monks concerning the following question:

I recently had to add some code that sets $ENV{TZ} to the correct local time. (Date::Manip requires this, and it wasn't already in my ENV on windows.) I've noticed that since doing that, when I call one perl script from another the localtime incorrectly returns GMT in the called script.
$ENV{'TZ'} = '-0400'; # also tried 'US/Eastern' with same result. print qq{---- $ENV{'COUNT'} ---- TZ: $ENV{'TZ'} localtime: } . scalar(localtime) . "\n"; $ENV{'COUNT'}++; exit if $ENV{'COUNT'} > 3; system("C:\\perl\\bin\\perl.exe C:\\cgi\\test");
The result is:
C:\FootPrints1\cgi>C:\perl\bin\perl.exe C:\cgi\test ---- ---- TZ: -0400 localtime: Thu Sep 6 10:46:07 2007 ---- 1 ---- TZ: -0400 localtime: Thu Sep 6 14:46:07 2007 ---- 2 ---- TZ: -0400 localtime: Thu Sep 6 14:46:07 2007 ---- 3 ---- TZ: -0400 localtime: Thu Sep 6 14:46:07 2007
I'm using ActiveState 5.8.8. When I try the same on Solaris with 5.8.1 it always shows the correct local time. I tried the following code after setting ENV{TZ}, but it had no effect on the result:
use POSIX(); POSIX::tzset();
Any ideas how I can make localtime give me the local time (while still setting ENV{TZ} to keep Date::Manip happy)? What settings does localtime depend on?

Thanks, Joe