Re: Converting a Complex Script to use CGI
- From: usenet@xxxxxxxxxxxxxxx
- Date: 28 Dec 2006 22:54:37 -0800
spud wrote:
How would I go about creating a script that asks some questions then
performs commands from them?
I presume you are using the CGI.pm module...
The problem seems to be that you are not separating out your runmodes
(states). Your program needs to see if any CGI paremeters have been
set. If not, print (only) the form and exit. If params are defined,
process them accordingly. For example (an EXTREMELY simplified
program):
#!/usr/bin/perl
use strict; use warnings;
use CGI qw{ :standard Dump };
print header();
if ( param() ) {
#parameters are defined - do something with them
"Your parameters are: ",
p( Dump() );
}
else {
#No parameters are known - show the input form
start_form(),
textfield({-name => 'stuff'}),
submit(),
end_form();
}
print end_html();
__END__
The first condition of the if{} block is executed only if parameters
have been passed to the program. If not, the else{} block is executed,
which prints the form (only). When the user fills out form elements
and hits the submit button the program is re-executed (with parameters
passed to the program), which invokes the processing defined in the
if{} block.
.
- References:
- Converting a Complex Script to use CGI
- From: spud
- Converting a Complex Script to use CGI
- Prev by Date: Re: learning perl::expect
- Next by Date: Re: HTTP POST without LWP
- Previous by thread: Re: Converting a Complex Script to use CGI
- Next by thread: learning perl::expect
- Index(es):