in reply to Re^2: Finding a remote time
in thread Finding a remote time

Localising the $ENV{TZ} isn't sufficient to prevent the effect being global, tzset() will need to be called after the value has been reverted to restore the timezone used by localtime(). For example:

use POSIX qw(tzset); use strict; + print scalar localtime(); + sub localtime_in { local $ENV{TZ} = 'EST'; + tzset(); + localtime(); } + print scalar localtime_in(); print scalar localtime();

Off the top of my head a way of fixing that would be something like:

use POSIX qw(tzset); use strict; + print scalar localtime(); + sub localtime_in { my $rc; my @rc; { local $ENV{TZ} = shift; tzset(); wantarray ? @rc = localtime() : $rc = localtime(); } tzset(); return wantarray ? @rc : $rc; } + print scalar localtime_in('EST'); print scalar localtime();

/J\