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--

In reply to (jeffa) Re: using strict; lots more errors by jeffa
in thread using strict; lots more errors by newatperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.