in reply to using strict; lots more errors
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.$query->param('Action','nothing yet'); # or $query->param(-name=>'Action', -value=>'nothing yet');
Let's say that your submit tag looks like this:
Then you can see if the user clicked that button like so:<input type="submit" name="Action">
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.if ($query->param('Action')) { # do stuff }
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 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.if (my $foo = $query->param('foo')) { #do stuff with $foo }
Now then about the why you get the 'print on closed filehandle' error question - you really should catch your errors by the way:
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;open PUBFILE, ">$PUBFILE" || die "do i have permission? $!";
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.use CGI::Carp qw(fatalsToBrowser);
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/
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'.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
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 | |
by jeffa (Bishop) on May 10, 2001 at 21:39 UTC |