> Hi
>
> I have a very simple cgi script that I have put onto a webserver. I want
> to write to a log file when it is run. My problem is that the open file
> command always fails (and I get the "openFailed" message in my browser).
> (even if i try opening for input it fails). I have created the file called
> log.dat in the same folder as the script (cgi-bin) and set attributes to
> read/write using chmod.
>
> Is there any easy way I can find out why the file cant be opened (is it
> permissions?).
You can get further help on what you need to know by using the $!
variable in your exit code. $! is a special variable (perldoc perlvar)
that tells you the reason why a particular action fails. See below.
Do I need to fully qualify the filepath? if so how do I do
> that? Is it because I'm not allowed to have log files in the cgi-bin
> folder?
>
Shouldn't, depends, possibly but not necessarily.
> Any help for an absolute beginner appreciated.
> steve
>
>
> #!/usr/local/bin/perl
>
use strict; #always
use warnings; #usually
> $Msg = "";
my $Msg = '';
>
> if( ! open (LOGFILE, ">> log.dat") ){
> $Msg = "OpenFailed";
$Msg = "Open failed: $!";
$Msg will now include the human readable version of why the open fails.
> }
> else {
> $Msg = "OpenWorked";
> #print LOGFILE $Msg;
> close (LOGFILE) ;
> }
>
> print "Content-type: text/html\n\n";
>
> print <<"EOF";
> <HTML>
>
> <HEAD>
> <TITLE>Result</TITLE>
> </HEAD>
> <BODY>
> <TABLE DIR=LTR BORDER>
> <CAPTION>$Msg</CAPTION>
> <TR>
> <TD>$Msg</TD>
> </BODY>
> </HTML>
> EOF
>
Give it a shot and see if that helps, if not post again...
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>