PDA

View Full Version : What is wrong here, please?


Philip M
01-29-2004, 12:05 PM
I have the following very simple fragment:


#!/usr/bin/perl

# Get the current day of the month (only $mthday is needed 1-31) #
$mthday = (localtime(time))[3];

### Make sure lastaccess.fil exists in cgi-bin directory and is CHMOD 777 ##

open (SENTOUT, "<lastaccess.fil");
$lastaccessed = <SENTOUT>;
close (SENTOUT);
if ($lastaccessed == $mthday) { # reminders have already been sent out today
exit();
}
open (SENTOUT, ">lastaccess.fil");
print SENTOUT ($mthday);
close (SENTOUT);

exit();


This generates an Internal Server Error, but for the life of me I cannot see why.

Confusingly it seems to work, as the content of lastaceess.fil is 29, today's date.

What simple silly thing have I overlooked? The script is CHMOD 755, in my cgi-bin obviously.

Paul-Ecchi
01-29-2004, 05:09 PM
instead of
print SENTOUT ($mthday);
use
print SENTOUT "$mthday";

Philip M
01-29-2004, 06:41 PM
Thanks for replying, Paul.

But it has not solved the problem.
Still get Internal Server Error

and I believe that print SENTOUT ($mthday); is correct syntax, and it certainly gives no problem in other scripts.

I STILL get the error when I comment out almost all the script, but as far as I can see the CHMOD settings are correct at 755 for the script and 777 for the data file.

But I am blessed if I can see what is wrong!

dswimboy
01-29-2004, 07:15 PM
I am assuming you are accessing this script from a browser. you are not giving the browser any information. this script may be fine for a command line, where no information needs to be returned. A web browser (and server) however expect information back. a header is necessary.

Philip M
01-29-2004, 08:41 PM
Thank you dswimboy! You have got it!

I had just worked out that what was missing was

print "Content-type: text/html\n\n";

Two or more hours wasted! 'Wat een ellende' as they say in Holland.