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

I have a module that uses Time::Local's timelocal function. It runs fine under Unix, but on some versions of Windows it spits out tons of errors. It seems that even a simple test program spits out tons of errors on Windows XP:
#!perl -w use warnings; use strict; use Time::Local; my $time = time; print "Epoch time: $time\n"; print "ctime time: ",scalar(localtime($time)),"\n"; print " localtime: ",join(", ",localtime($time)),"\n"; print " timelocal: ",timelocal(localtime($time)),"\n";

Reports:

Epoch time: 1111461913 ctime time: Mon Mar 21 22:25:13 2005 localtime: 13, 25, 22, 21, 2, 105, 1, 79, 0 Use of uninitialized value in integer addition (+) at C:/Perl/lib/Time +/Local.pm line 76. Use of uninitialized value in integer multiplication (*) at C:/Perl/li +b/Time/Loc al.pm line 76. Use of uninitialized value in integer multiplication (*) at C:/Perl/li +b/Time/Loc al.pm line 76. Use of uninitialized value in pack at C:/Perl/lib/Time/Local.pm line 6 +7. Use of uninitialized value in pack at C:/Perl/lib/Time/Local.pm line 6 +7. Use of uninitialized value in integer addition (+) at C:/Perl/lib/Time +/Local.pm line 68. Use of uninitialized value in integer addition (+) at C:/Perl/lib/Time +/Local.pm line 69. Use of uninitialized value in integer addition (+) at C:/Perl/lib/Time +/Local.pm line 67. timelocal: 1111461913

Turning warnings off seems not to be an option; the module is spitting out the warnings under Test::More, which seems to always have warnings turned on.

Any ideas? Should I just put this in my release notes?

Update: Sorry for the slow response; I didn't get a chance to get back in front of a Windows machine last night.

Here is some more information:

As for the code in Time::Local, part of the problem is that $SecOff is somehow undefined, at least when I run it through the debugger. Here are a few lines:

# Line 24 immediately below my $SecOff = 0; # Line 66 immediately below sub _daygm { $_[3] + ($Cheat{pack("ss",@_[4,5])} ||= do { my $month = ($_[4] + 10) % 12; my $year = $_[5] + 1900 - $month/10; 365*$year + $year/4 - $year/100 + $year/400 + ($month*306 + 5)/10 +- $Epoc }); } # Line 75 immediately below sub _timegm { my $sec = $SecOff + $_[0] + 60 * $_[1] + 3600 * $_[2]; no integer; $sec + 86400 * &_daygm; }

Replies are listed 'Best First'.
Re: Lots of errors from Time::Local on Windows
by bart (Canon) on Mar 22, 2005 at 08:58 UTC
    Like the other posters, I don't get the same warnings here. It smells like a buggy version of Time::Local, while the problem may also only occur with certain values of $time. So I copied your value.
    $^W = 1; use Time::Local; print "Perl: $]\n"; print "VERSION: $Time::Local::VERSION\n"; my $time = '1111461913'; print "Epoch time: $time\n"; print "ctime time: ",scalar(localtime($time)),"\n"; print " localtime: ",join(", ",localtime($time)),"\n"; print " timelocal: ",timelocal(localtime($time)),"\n";

    Results:

    IndigoPerl 5.6.1 (on Windows, of course), with an ancient, $VERSION-less version of Time::Local, apparently.
    Perl:       5.006001
    Use of uninitialized value in concatenation (.) or string at test.pl line 5.
    VERSION:    
    Epoch time: 1111461913
    ctime time: Tue Mar 22 04:25:13 2005
     localtime: 13, 25, 4, 22, 2, 105, 2, 80, 0
     timelocal: 1111461913
    
    On ActivePerl 5.8.3 (on Windows):
    Perl:       5.008003
    VERSION:    1.07
    Epoch time: 1111461913
    ctime time: Tue Mar 22 04:25:13 2005
     localtime: 13, 25, 4, 22, 2, 105, 2, 80, 0
     timelocal: 1111461913
    

    I am quite convinced that the fact that this is on Windows, is irrelevant. Now I am

    curious what $Time::Local::VERSION you have, and what's on its lines 76 and 67 through 69, where the warnings come from.

    p.s. Also note that the figures that come out of it, depend on your time zone. Perhaps there's a connection to that, too. So, what time zone are you in? I'm in CET. Summer time starts in a week. Ooh, perhaps another clue!

Re: Lots of errors from Time::Local on Windows
by Tanktalus (Canon) on Mar 22, 2005 at 03:39 UTC

    What version of perl? Time::Local? I don't get these problems here (for a very vague definition of "here"). Perl 5.8.0 from ActiveState, and Time::Local 1.04, and no errors or warnings of any kind for your script.

    (Telecommuting - my windows development box is 3000km away, so "here" is meant only in the most virtual of senses.)

Re: Lots of errors from Time::Local on Windows
by bart (Canon) on Mar 22, 2005 at 14:48 UTC
    part of the problem is that $SecOff is somehow undefined, at least when I run it through the debugger.

    That's not what it looks like to me. Instead, it would appear to me that @_ somehow is empty, or partly empty, or filled with a few undefined values. At least, the number of warnings and the line number they occur at, would agree with it: pack with empty $_[4] and $_[5] (line 67), addition with empty $_[3] (line 68), $_[5] (line 69), and $_[3] (line 67).

    I do not see what could cause that, though. It's an odd error — perhaps even a Perl bug for version 5.8.6. It's the last line in the sub _timegm I currently have under suspicion:

    $sec + 86400 * &_daygm;
    Can anybody confirm @_ is passed unaltered, on 5.8.6, when a sub is called with "&" and without parens?
Re: Lots of errors from Time::Local on Windows
by chas (Priest) on Mar 22, 2005 at 03:54 UTC
    No errors at all using v5.6.1 (Siemens Perl) in Windows 98 or with Activestate v5.8.0 (same OS).
    chas
    (Update: Strangely, my Time::Local modules don't seem to have a version number in the file. The latest version on CPAN does (1.11) so mine is likely an earlier version. I'd probably compare the Local.pm modules on Unix and Windows to see what's going on...)