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

I'm stumped. I've got a script with the following three lines in it:
my $yesterday = time(); $yesterday = $yesterday - 86400; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($ +yesterday);
It returns a 500 Internal Server Error. I have no way of checking the error logs on this particular site and the server apparently does not have CGI::Carp installed (and I'd like to avoid installing it manually). I'm using a site on godaddy's server, Perl version 5.6. If I change the third line above to simply localtime(time) there's no problem. The script runs without errors. Anybody have an idea as to what's going on?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
$nysus = $PM . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: CGI script choking on localtime function call
by rhesa (Vicar) on Feb 16, 2006 at 04:40 UTC
    not that i have a perl5.6 handy, but this snippet works fine here. Is there a possibility that your code dies somewhere else based on the resulting values of localtime?

    Tip: wrap the offending part in an eval { ... } or die $@; block. See what $@ reports for you.

      Ah, yes. I'm a boob. The problem was with how the time values were used later on in the code. I was using the data returned by the localtime function to open a file that had a timestamp for its name. By subtracting 86400 seconds, I was trying to open a file that didn't exist. Thanks for snapping me out of my idiocy.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
      $nysus = $PM . $MCF;
      Click here if you love Perl Monks