in reply to Web form to alter files is writing to file before submit button is pressed.

A common way is to use the param() function of CGI.pm to see whether any parameters were sent. That way you don't need a named submit button at all, which you may not always have. (Or you may have more than one.)

if( $cgi->param ){ # do stuff with submitted form data } else { # print form }

Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.

Replies are listed 'Best First'.
Re^2: Web form to alter files is writing to file before submit button is pressed.
by Lady_Aleena (Priest) on Mar 11, 2012 at 19:24 UTC

    aaron, so this checks all of the parameters I set, and if any of them are defined, then it will do stuff with the submitted form data. There may be one small problem with having to check all of those parameters which is some of my files will have tens of thousands of parameters to check. I am not overly worried about speed, but would that slow things down a little?

    Have a cookie and a very nice day!
    Lady Aleena

      That's not quite what it does. $cgi->param returns a list of the names of all the form fields submitted by the browser. So if any are submitted, it will return true, regardless of their values. Only when the URI is requested without any POST data -- as when the page is first loaded, typically -- will it return nothing, giving a false status to the if statement. So it's not really "checking all the parameters." To the extent that it loads them into some sort of structure, I'm fairly sure that was already done when you created the CGI object, so there's not much cost here.

      On your last question: If you have forms with that many fields, I think you'll run into bottlenecks at the browser or the web server -- with the maximum POST data size, for instance -- long before counting the items in a large array slows down your Perl script. With a form that large, I'd be more concerned about usability and maintainability than with speed.

      Aaron B.
      My Woefully Neglected Blog, where I occasionally mention Perl.