in reply to using strict; lots more errors

You set the variable of a parameter like so:
$query->param('Action','nothing yet'); # or $query->param(-name=>'Action', -value=>'nothing yet');
see CGI for more details. But don't set this value. The problem is that you are trying to compare it to some value - don't do that. If the parameter you are looking for is not there (as is the case with 'Action' the first time the form is loaded), then param() will return undefined. If you try to compare that to a value, you will get a warning - not fatal, just annoying.

Let's say that your submit tag looks like this:

<input type="submit" name="Action">
Then you can see if the user clicked that button like so:
if ($query->param('Action')) { # do stuff }
no need to check it's value if there is only one button. The mere existance of the query string variable 'Action' is enough to pass the test.

A lot of times, I find myself having a CGI script that really only needs one variable from the user, then I use something like this:

if (my $foo = $query->param('foo')) { #do stuff with $foo }
If you can, please persuse the documention for CGI, also Ovid has a great tutorial, and merlyn has a ton of tricks free of charge at his site.

Now then about the why you get the 'print on closed filehandle' error question - you really should catch your errors by the way:

open PUBFILE, ">$PUBFILE" || die "do i have permission? $!";
Because otherwise you will not know why the open failed. You will also want to add this line at the beginning of your script, say just right below use CGI;
use CGI::Carp qw(fatalsToBrowser);
this will allow you to see the output of the die in the browser. Another good way to look for CGI run time errors is by 'tailing' the error log file. Each die is systematically logged behind the scenes to the web server's error log file.

So, why the error? I am just guessing here, but 9 out of 10 reasons why you can't create a file from a CGI script is because of permissions. Take a look at this directory listing of ~jeff/public_html/wooden/

drwxrwxr-x 2 jeff jeff 4096 Apr 3 01:37 ./ drwxr-xr-x 19 jeff jeff 4096 May 8 23:46 ../ -rw-rw-r-- 1 jeff jeff 11781 Mar 31 01:10 back.jpg -rw-rw-r-- 1 jeff jeff 2078 Mar 31 01:11 bar.jpg -rw-rw-r-- 1 jeff jeff 274 Apr 3 01:37 index.html
the first line tells the permission for directory wooden - user jeff can create files in it, group jeff can create files in it, but nobody else can (no pun intended). The web server runs as a user - this user is set by the administrator, and usually something like 'nobody' or 'www' or 'www-data'. Not 'jeff'.

To fix this, you either need to change the group to be the same as the one the web server uses (have to have root access to do this - talk to your admin), or set the permissions of your directory where the files are to be created to 777 (via chmod), writeable by every one ON THAT COMPUTER, not the web.

whew, hope this helps ;)

Jeff

R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
L-L--L-L--L-L--L-L--L-L--L-L--L-L--

Replies are listed 'Best First'.
Re: (jeffa) Re: using strict; lots more errors
by buckaduck (Chaplain) on May 10, 2001 at 19:49 UTC
    open PUBFILE, ">$PUBFILE" || die "do i have permission? $!";
    I think you mean this instead: open PUBFILE, ">$PUBFILE" or die "do i have permission? $!"; Or at least this: open (PUBFILE, ">$PUBFILE") || die "do i have permission? $!"; buckaduck
      DOH!

      i am going to leave it just to show how much it pays to pay attention

      jeff "that should be a new feature so i am correct" a