Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

%ENV{TZ} does not always affect CORE::localtime() under multi-threaded perl

by dda (Friar)
on Apr 16, 2003 at 20:02 UTC ( [id://251018]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks!

Consider the following code:
$ENV{TZ} = "DST"; # something different than current TZ print localtime();
The code does not work properly at each invocation. Looks like $ENV{TZ} is cached somewhere. If I add some debug messages, like 'warn "$ENV{TZ}"', before calling localtime(), it works always.

The problem exists only at one of our linux boxes, with perl, v5.8.0 built for i386-linux-thread-multi. Another machines with perl 5.6.1, single-treaded, are not affected.

Probably it is a known issue?

--dda

  • Comment on %ENV{TZ} does not always affect CORE::localtime() under multi-threaded perl
  • Download Code

Replies are listed 'Best First'.
Re: %ENV{TZ} does not always affect CORE::localtime() under multi-threaded perl
by Chmrr (Vicar) on Apr 16, 2003 at 22:35 UTC

    This is a problem on the C level, I believe. The localtime(3) call does not always check the current value of the TZ environment variable. To force it to do so, POSIX-compliant systems should use the tzset(3) call.

    You can imitate this in perl via:

    use POSIX; $\ = "\n"; $ENV{TZ} = "EST"; POSIX::tzset(); print scalar localtime(); $ENV{TZ} = "DST"; POSIX::tzset(); print scalar localtime();

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

      This works fine from a script, but does not work under mod_perl_2! Do you have any suggestions as to how I might go about getting this working under mod_perl_2?????
Re: %ENV{TZ} does not always affect CORE::localtime() under multi-threaded perl
by The Mad Hatter (Priest) on Apr 16, 2003 at 20:23 UTC
    I have perl v5.8.0 built for i686-linux-thread-multi-ld and doing
    perl -e '$ENV{TZ} = "DST";print scalar localtime(), "\n";'
    works fine for me.
      Could you please try this:
      perl -e '$ENV{TZ} = "EST";print scalar localtime(), "\n";$ENV{TZ} = "DST";print scalar localtime(), "\n";'
      It works correctly at 5.6.1 and misbehaves at 5.8.0

      --dda

        What dda means to say is:

        here is the output on a redhat 8, perl 5.8.0 (multithreaded) box (actually we have tried 3 redhat 8 boxes):

        perl -e '$ENV{TZ} = "EST";print scalar localtime(), "\n";$ENV{TZ} = "DST";print scalar localtime(), "\n";'
        Wed Apr 16 15:47:41 2003
        Wed Apr 16 15:47:41 2003


        whereas on a redhat 7.2, perl 5.6.1 box, the output is
        Wed Apr 16 15:42:25 2003
        Wed Apr 16 20:42:25 2003


        and on a freebsd box, perl 5.8.0, the output is also correct, i.e.
        Wed Apr 16 15:42:25 2003
        Wed Apr 16 20:42:25 2003

        perl 5.6.1 under cygwin seems to manifest the problem also.
        Hmmmm, I see what you mean. Seems like a bug (like you said).

        Just to let every know, output is:

        Wed Apr 16 15:56:22 2003 Wed Apr 16 15:56:22 2003

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://251018]
Approved by Paladin
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 09:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found