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

Hi - I am trying to set up a discussion board and am having problems. I have an html file call bbentry.html which allows the user to enter name, email and comments. It calls a script bb.pl and then this writes to bb.html. I have included the whole script (sorry if it is too much info) I get an error message that it can not find the temporary file but I am not sure what is wrong. Then if I run it again, I get Discussion Board in use. Please try again later. Can you help?? Thank you in advance. Alice
#!c:\perl\bin\perl.exe # ensure all fatals go to browser during debugging and set-up use CGI::Carp 'fatalsToBrowser'; require "c:\\webserver\\osarr.org\\www\\cgi-bin\\cgi-lib.pl"; &ReadParse; print &PrintHeader; $url="http://www.osarr.org/member/bboard/bb.html"; $bbfile="c:\\webserver\\osarr.org\\www\\member\\bboard\\bb.html"; unless (-e $bbfile) { print <<"PrintTag"; <html><body> <p>$bbfile is not found- something is wrong</p> </body></html> $tempfile="c:\\webserver\\osarr.org\\www\\member\\bboard\\bb.html"; if (($in{'name'} eq "") || ($in{'email'} eq "") || ($in{'comments'} eq "")) { print <<"PrintTag"; <html><body> Please complete all fields before submitting your message to the OSARR + Discussion Board. <br><br>Please complete:<br> PrintTag if ($in{'name'} eq "") { print "\n Your Name\n"; } if ($in{'email'} eq "") { print "\n Your Email Address\n"; } if ($in{'comments'} eq "") { print "\n Your Comments\n"; } print "</body></html>\n"; exit(0); } if (-e "glock.fil") { print <<"PrintTag"; <html><body> The OSARR Discussion Board is in use. Please try again later. </body></html> PrintTag exit(0); } open(LOCKFILE, ">glock.fil"); open(BBFILE,"$bbfile") ||die "Can't find the discussion board.\n"; @indata=<BBFILE>; close(BBFILE); open(TEMPFILE,">$tempfile") || die "Can't find this temporary file wha +t is wrong. \n"; foreach $i (@indata) { chomp($i); #copy line to temp file print TEMPFILE "$i\n"; #insert new form data below placeholder if ($i =~ /<!--BEGINNING-->/i) { print TEMPFILE "<p><a href=\"mailto:$in{'email'}\">"; print TEMPFILE "$in{'name'}"; print TEMPFILE "</a>"; print TEMPFILE "<br>"; print TEMPFILE "$in{'comments'}</p><hr>\n\n"; } } close (TEMPFILE); rename("$bbfile", "$bbfile.old"); rename("$tempfile", "$bbfile"); #close and unlink lock.fil close (LOCKFILE); unlink("glock.fil"); print <<"PrintTag"; <html><body> Your entry has been posted to the OSARR Discussion Board<Br><br> View <a href="$url">OSARR Discussion Board</a> </body></html> PrintTag #endprogram

Replies are listed 'Best First'.
Re: Having trouble with a Discussion Board
by b10m (Vicar) on Jan 28, 2004 at 18:28 UTC

    Based on your information, I'd say this line is the culprit:

    open(TEMPFILE,">$tempfile") || die "Can't find this temporary file what is wrong. \n";

    This basically says, open $tempfile for (over)writing, or stop (die). The error message is not very helpful though, for I bet it's a file permissions problem ;) $tempfile is defined as:

    $tempfile="c:\\webserver\\osarr.org\\www\\member\\bboard\\bb.html";

    And later on I read:

    rename("$tempfile", "$bbfile");

    So, basically, your script opens a file ($tempfile), writes something to it, and renames it to $bbfile. After that, (when the script runs again) $tempfile is gone (you already renamed it) so Perl tries to make a new file, which probably fails due to the lack of permissions. Make sure that the user under which the web-server runs, has write permissions in c:\webserver\osarr.org\www\member\bboard\

    To double check this permissions problem, you might want to change the not-so-helpful error message into something like:

    open(TEMPFILE,">$tempfile") || die("Can't open $tempfile: $!");

    HTH

    --
    b10m

    All code is usually tested, but rarely trusted.
      Thank you - I changed it and the error message I got was: Can't open : No such file or directory at c:\webserver\osarr.org\www\cgi-bin\bb.pl line 67. which is this line: $tempfile="c:\\webserver\\osarr.org\\www\\member\\bboard\\bbtemp.html"; I checked with the hosting co. and they said that the permissions are set read and write. Do I also need execute set on? Thanks What does this mean?
        the error message I got was: Can't open : No such file or directory at c:\webserver\osarr.org\www\cgi-bin\bb.pl line 67.

        If you took my code (altered die statement) and pasted it in your script verbatim, than you experience something odd, for it doesn't return the value of the $tempfile variable in the die statement, alas, it looks like either you made a typo somewhere, or $tempfile is not set right. I take it this is a script you fetched from some online source, but if you're willing to improve it a little (call that a bunch) you might want to look into strict to prevent typos.

        Looking at your original code again, I now notice (either I missed it before, or you changed it in the meanwhile) the following, which doesn't make much sense to me:

        $bbfile="c:\\webserver\\osarr.org\\www\\member\\bboard\\bb.html"; $tempfile="c:\\webserver\\osarr.org\\www\\member\\bboard\\bb.html"; [...] rename("$bbfile", "$bbfile.old"); rename("$tempfile", "$bbfile");

        This is not going to work. Both $bbfile and $tempfile point to the same file. The first rename function, changes bb.html into bb.html.old, leaving $tempfile clueless, for the file bb.html is gone. Try changing the value of $tempfile to something like:

        $tempfile="c:\\webserver\\osarr.org\\www\\member\\bboard\\bb.html.tmp" +;
        which is this line: $tempfile="c:\\webserver\\osarr.org\\www\\member\\bboard\\bbtemp.html";

        No, the line number returned, will most likely point to:

        open(TEMPFILE,">$tempfile") || die("Can't open $tempfile: $!");

        That line contains the die statement that killed your script, if I recall correctly. I also wonder why the file in $tempfile is bbtemp.html now again. It doesn't show that in your original code, as discussed above.

        I checked with the hosting co. and they said that the permissions are set read and write. Do I also need execute set on? Thanks What does this mean?

        I'm not very familiar with the Windows file system, so other monks can probably explain this in greater detail, but if it's anything like a *NIX file system, you will need executable rights on all the directories leading to the file in question:

        c:\webserver\ c:\webserver\osarr.org\ c:\webserver\osarr.org\www\ c:\webserver\osarr.org\www\member\ c:\webserver\osarr.org\www\member\bboard\

        Then you need write access to the c:\webserver\osarr.org\www\member\bboard\ directory. Not the specific file, but the entire directory, for it seems that this script will recreate the $tempfile every time. Also make sure that the web-server is able to write to that directory, not just you, using your own account. The hosting company should know this and how to set it all up, so that's their burden ;) Also make sure these directories actually exist, and you didn't make a typo in them.

        So, now back to the new error message (excuse me for the long post but I try to cover as much as possible) Can't open : No such file or directory at c:\webserver\osarr.org\www\cgi-bin\bb.pl line 67. Please triple check what line 67 exactly is and post that line specifically as you have it. The error you get looks to me like your code looks something like:

        open(TEMPFILE, "$tempfile") || die("Can't open $tmpfile: $!");

        Please not the > sign in my example, and check the spelling of the $tempfile in the die statement.

        --
        b10m

        All code is usually tested, but rarely trusted.
Re: Having trouble with a Discussion Board
by ysth (Canon) on Jan 28, 2004 at 18:32 UTC
    Change:
    open(TEMPFILE,">$tempfile") || die "Can't find this temporary file wha +t is wrong +. \n";
    to
    open(TEMPFILE,">$tempfile") || die "Can't find this temporary file: $! +\n";
    The $! variable will contain an error message explaining why the open failed. You should almost always include it in error messages about failures of system routines.