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

The wonderful thing about explaining a problem is how much you can learn about it by trying to tell someone else about it. I was in the middle of typing this SoPW and about to claim "I can't pare this down." And then I figured out a really simple, minimal example that exhibits the problem.

The system: Windows running ActiveState 5.8.6. Note that 5.8.6 running on other platforms, thus far, have not exhibited this problem which is annoying because Windows is the only platform where I need to run this piece of code. (I'm not sure why this is.)

The problem: convert a timestamp, e.g., 2005-07-15, to a epoch-time for futher manipulations.

The symptoms:

Use of uninitialized value in integer addition (+) at E:/build/SDKs/perl5.8.6/lib/Time/Local.pm line 76 (#1) (W uninitialized) An undefined value was used as if it were alread +y defined. It was interpreted as a "" or a 0, but maybe it was a mi +stake. To suppress this warning assign a defined value to your variables. To help you figure out what was undefined, perl tells you what ope +ration you used the undefined value in. Note, however, that perl optimiz +es your program and the operation displayed in the warning may not necessa +rily appear literally in your program. For example, "that $foo" is usually optimized into "that " . $foo, and the warning will refer +to the concatenation (.) operator, even though there is no . in your program. Use of uninitialized value in integer multiplication (*) at E:/build/SDKs/perl5.8.6/lib/Time/Local.pm line 76 (#1) Use of uninitialized value in pack at E:/build/SDKs/perl5.8.6/lib/Time +/Local.pm line 67 (#1) Use of uninitialized value in integer addition (+) at E:/build/SDKs/perl5.8.6/lib/Time/Local.pm line 68 (#1) Use of uninitialized value in integer addition (+) at E:/build/SDKs/perl5.8.6/lib/Time/Local.pm line 69 (#1) Use of uninitialized value in integer addition (+) at E:/build/SDKs/perl5.8.6/lib/Time/Local.pm line 67 (#1)
In addition, when going in with a debugger, I find that the true cause is that localtime($time) returns an empty list if $time is -2147483648 (which is the minimum integer as calculated by the module).

However. This is not a problem if I use Time::Local all by itself. For example, perl -MTime::Local -e "print timelocal(0,0,0,15,6,2005),$/" works just perfectly. So obviously I'm doing something in another module to screw it up.

What am I doing to screw it up? Well, the astute reader will note that these are all mere warnings. And that my example above didn't turn on warnings. And, of course, the clincher is the title of this node. :-)

If I use perl -MTime::Local -we "print timelocal(0,0,0,15,6,2005),$/", I get:

Use of uninitialized value in integer addition (+) at E:/build/SDKs/pe +rl5.8.6/lib/Time/Local.pm line 76. Use of uninitialized value in integer multiplication (*) at E:/build/S +DKs/perl5.8.6/lib/Time/Local.pm line 76. Use of uninitialized value in integer multiplication (*) at E:/build/S +DKs/perl5.8.6/lib/Time/Local.pm line 76. Use of uninitialized value in pack at E:/build/SDKs/perl5.8.6/lib/Time +/Local.pm line 67. Use of uninitialized value in pack at E:/build/SDKs/perl5.8.6/lib/Time +/Local.pm line 67. Use of uninitialized value in integer addition (+) at E:/build/SDKs/pe +rl5.8.6/lib/Time/Local.pm line 68. Use of uninitialized value in integer addition (+) at E:/build/SDKs/pe +rl5.8.6/lib/Time/Local.pm line 69. Use of uninitialized value in integer addition (+) at E:/build/SDKs/pe +rl5.8.6/lib/Time/Local.pm line 67. 1121407200
But still, only on Windows. So I think I've found a bug. In Time::Local or localtime, I'm not sure. Not really relevant now - I just need to solve this.

Finally, the question: how do I turn off warnings for another module? I've tried:

{ no warnings; no strict; no diagnostics; use Time::Local; }
but it hasn't had any affect. Is there another option? Thanks!

Replies are listed 'Best First'.
Re: Time::Local and warnings
by borisz (Canon) on Aug 04, 2005 at 18:59 UTC
     perl -MTime::Local -we "print timelocal(0,0,0,15,6,2005),$/" works fine for me with perl 5.8.4. To turn off warnings just put a no warnings; into the scope of the calling function.
    use Time::Local; ... { no warnings; print timelocal(0,0,0,15,6,2005),$/; }
    or use
    { local $^W; ... }
    Boris

      The no warnings option doesn't work because it's a compile-time directive. However, the local $^W option works perfectly. I knew there was a solution out there, but I had never had to use it before. Thanks a lot, borisz++! That will work wonderfully until I can convince the infrastructure team to upgrade Time::Local for their shared perl environment!

Re: Time::Local and warnings
by NetWallah (Canon) on Aug 04, 2005 at 19:06 UTC
    I could not reproduce your problem on perl v5.8.3 and Time::Local ver 1.07. I get no warnings, and a different answer:
    > perl -MTime::Local -we "print timelocal(0,0,0,15,6,2005),$/" ---output-- 1121410800
    Your problem may be related to this note in Time::Local, Changes for 1.11

    "1.11 2005-02-09 - Try to make detection of supported epoch range a little smarter.
    The detection was allowing negative epochs on Win32 but apparently this doesn't work, and trying to pass a pre-epoch date in just causes a lot of warnings.
    ".

         "Income tax returns are the most imaginative fiction being written today." -- Herman Wouk

      I forwarded my original post to the author via http://rt.cpan.org, and got back that he thinks this is fixed in 1.11. So that is in agreement with your assessment - I just have to convince the infrastructure team to move up. In the meantime, I have a workaround that works.

      BTW - your output will be different based on your timezone. I am using timelocal, afterall, and not timegm ;-)

Re: Time::Local and warnings
by sgifford (Prior) on Aug 04, 2005 at 19:14 UTC
    I can't offer advice, only sympathy. I suspect that it's a bug in Time::Local, but Windows isn't my primary platform so I didn't look much further.
Re: Time::Local and warnings
by PodMaster (Abbot) on Aug 05, 2005 at 06:04 UTC
    But still, only on Windows. So I think I've found a bug. In Time::Local or localtime, I'm not sure. Not really relevant now - I just need to solve this.
    Don't use the -w switch, use warnings; instead.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Don't use the -w switch, use warnings; instead.

      Only curiosity: Why? Is there any major difference or anything that can bit me in the worst moment?

      I use to put the -w switch so, if I don't use anything "new", I can run on both 5.8.x and 5.005 (default Solaris perl)

        Why? So you only get warnings from code you write, not Time::Local.

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.