Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

CGI script choking on localtime function call

by nysus (Parson)
on Feb 16, 2006 at 04:30 UTC ( [id://530588]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found