in reply to Finding a remote time

Thanks for all your replies. In the end I went for fletch's suggestion to localise $ENV{ TZ }, because I needed to compute the difference between local time and the remote time and could not permit the code to switch to remote time throughout. Another factor in choosing the most convenient solution was that it was easier to use core modules only rather than require module installation all the way down the production line (dev -> test -> QA -> uat -> prod.) for so small a piece of code.

Update: OK to be honest I did not explicitly use 'local' because the tzset had to be repeated anyway. What I actually did was more like:

sub RemoteTime { my $realtz = $ENV{ TZ }; my ( @return, $return ); my $wantarray = wantarray; $ENV{ TZ } = shift; tzset; if ( $wantarray ) { @return = localtime(); } else $return = localtime(); } $ENV{ TZ } = $realtz; tzset; return $wantarray ? @return : $return; }

-M

Free your mind

Replies are listed 'Best First'.
Re^2: Finding a remote time
by nothingmuch (Priest) on Jul 17, 2006 at 20:04 UTC
    If you need to compute stuff you really ought to use DateTime - it takes care of all the nasty details of time math for you.
    -nuffin
    zz zZ Z Z #!perl
    A reply falls below the community's threshold of quality. You may see it by logging in.