use strict; use CGI; my $CGI = new CGI; print $CGI->header, $CGI->start_html, $CGI->pre; foreach my $name ($CGI->param) { print "$name = ", $CGI->param($name), "\n"; }
When a form is submitted to a Perl script that uses CGI.pm, the form variables are magically available via the param() method.
The param() method works two ways: when called with no args, it returns a list of the available form variables. When called with a single argument(the name of the form variable you want the value of) it returns the value of that variable.
The big gotcha is dealing with multiple-valued variables, then param() will return a list of the values. Change the line inside the for loop to this:
if you want to handle multiple-valued variables. Otherwise the script will only print the last assigned value. Jeffmy $value = join(",", $CGI->param($name)) || ''; print "$name = $value\n";
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: I know this is very easy
by jeffa
in thread Printing variables from CGI form (was: I know this is very easy)
by new_2_perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |