in reply to Re^4: Time zones
in thread Time zones

Assuming you're not running under mod_perl, I think you may have misunderstood what ikegami meant by changing %ENV only affects perl and it's children. This change will only affect the process you change it in, and any processes started by that process, with a call to fork or the equivalent. Even under mod_perl, I suspect it will work OK if you localize it.

Changing %ENV does not affect any other programs on the system, whether they are Perl scripts or otherwise. It doesn't even affect other running copies of the same script.

Replies are listed 'Best First'.
Re^6: Time zones
by Anonymous Monk on Sep 27, 2004 at 20:25 UTC
    Okay! Since is was local and in a block that's what I tought might be happening but I wasn't really sure. Thaks for everyones patience. I ran the following code on a machine that is Eastern Time. It printed out the same time in all the print statements.
    use strict; use warnings; print scalar(localtime),"\n"; { local $ENV{'TZ'} = 'GMT'; print scalar(localtime),"\n"; local $ENV{'TZ'} = 'EST5EDT'; print scalar(localtime),"\n"; } print scalar(localtime),"\n";
      It should have printed different times right? Boy, this would be a whole lot easier the other way around. I could just call gmtime() on an EST box. Too bad I can't call estime() from a GMT!

      Yup, it did for me too. Guess you'll have to try one of the other ideas posted here. :)

      FWIW, it does work if you set TZ before starting Perl:

      $ TZ='GMT' perl -e 'print localtime()."\n"'; Mon Sep 27 21:11:30 2004 $ TZ='EST5EDT' perl -e 'print localtime()."\n"'; Mon Sep 27 17:11:38 2004 $ TZ='MST' perl -e 'print localtime()."\n"'; Mon Sep 27 14:11:50 2004