why cgi print out everything to the page?

R

robertchen117

The code is below,
Why on the page, it will also print out the name according to these
two lines :
$name = param('name'),
$name =~ s/\^/\\^/,



# CGI script that creates a fill-out form
# and echoes back its values.

use CGI qw/:standard/;
print header,
start_html('A Simple Example'),
h1('A Simple Example'),
start_form,
"What's your name? ",textfield('name'),p,
"What's the combination?", p,
checkbox_group(-name=>'words',
-values=>['eenie','meenie','minie','moe'],
-defaults=>['eenie','minie']), p,
"What's your favorite color? ",
popup_menu(-name=>'color',
-values=>['red','green','blue','chartreuse']),p,
submit,
end_form,
hr;

if (param()) {
$name = param('name'),
$name =~ s/\^/\\^/,
print "Your name is",em(param('name')),p,
"The keywords are: ",em(join(", ",param('words'))),p,
"Your favorite color is ",em(param('color')),
hr;
}
 
M

Mumia W.

The code is below,
Why on the page, it will also print out the name according to these
two lines :

I don't understand the question. Perhaps you meant to ask "How do I
print the name after having preformed these changes:"
$name = param('name'),
$name =~ s/\^/\\^/,



# CGI script that creates a fill-out form
# and echoes back its values.

Even though the example in CGI.pm doesn't use them, it's best to use
strictures and warnings.

use strict;
use warnings;

use CGI qw/:standard/;
print header,
start_html('A Simple Example'),
h1('A Simple Example'),
start_form,
"What's your name? ",textfield('name'),p,
"What's the combination?", p,
checkbox_group(-name=>'words',
-values=>['eenie','meenie','minie','moe'],
-defaults=>['eenie','minie']), p,
"What's your favorite color? ",
popup_menu(-name=>'color',
-values=>['red','green','blue','chartreuse']),p,
submit,
end_form,
hr;

if (param()) {

my $name;
$name = param('name'),
$name =~ s/\^/\\^/,

Why are you putting commas rather than semicolons after these two lines?

print "Your name is",em(param('name')),p,
"The keywords are: ",em(join(", ",param('words'))),p,
"Your favorite color is ",em(param('color')),

p, "Transformed name: @{[ escapeHTML($name) ]}",
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top