#!/usr/bin/perl
#sbowl.cgi - saves form data to a file, and creates a dynamic
print "Content-type: text/html\n\n";
use CGI qw(:standard -debug);
use strict;
#declare variables
my ($sea,$pitt);
#assign input items to variables
$sea= param('Seahawks');
$pitt = param('Steelers');
#validate input data
if ($sea or $pitt eq "") {
push(@errors, "Enter a score.");
}
#determine size of @errors array
$size = @errors;
#create Web page
if ($size == 0) {
print "<HTML>\n";
print "<HEAD><TITLE>SUPERBOWL XL</TITLE></HEAD>\n";
print "<BODY><H2>Visit your predicted winner's website</H2><BR>\n";
if ($sea < $pitt) {
print "You picked the Seahawks: www.seahawks.com"\n";
}
else
{
if ($sea > $pitt) {
print "You picked the Steelers: www.steelers.com"\n";
}
else
{
if ($sea = $pitt) {
print "You predicted a tie: www.nfl.com\n";
}
else
{
print "You didn't pick a winner";
}
}
}
print "</BODY>\n";
print "</HTML>\n";
}
else {
#display error page
print "<html><head><title></title></head>\n";
print "<body>\n";
print "<h2>Please press your browser's Back button to \n";
print "enter a score.\n";
print "</body></html>\n";
}
print "You picked the Seahawks: www.seahawks.com"\n";
print "You picked the Steelers: www.steelers.com"\n";
there is an extra " before \n at the end that is going to kill the script.
@errors has never been declared with "my":
push(@errors, "Enter a score.");
you can add it to your list of variables:
#declare variables
my ($sea,$pitt,@errors);
and $size has the same problem:
$size = @errors;
change it to:
my $size = @errors;
this section is not correct:
if ($sea or $pitt eq "") {
change it to:
if ($sea eq "" or $pitt eq "") {
OK, so now you see what was wrong with the script, here it is cleaned up and converted to using the CGI module:
#!/usr/bin/perl
#sbowl.cgi - saves form data to a file, and creates a dynamic
use CGI qw(:standard);
use strict;
#assign input items to variables
my $sea= param('Seahawks');
my $pitt = param('Steelers');
print header;
#validate input data
if ($sea eq "" or $pitt eq "") {
print start_html,
h2(q~Please press your browser's Back button to enter a score~),
end_html;
exit;
}
print start_html('SUPERBOWL XL'),
h2(q~Visit your predicted winner's website~);
if ($sea < $pitt) {
print "You picked the Seahawks: www.seahawks.com\n";
}
elsif ($sea > $pitt) {
print "You picked the Steelers: www.steelers.com\n";
}
elsif ($sea == $pitt) {
print "You predicted a tie: www.nfl.com\n";
}
else {
print "You didn't pick a winner";
}
print end_html;
Thanks for your help! I need to keep checking my code, I get so tired of looking at it I forget to look for little mistakes like mistyping or putting in " where I shouldn't.
Try
print "<A HREF=\"http://www.example.com\">Seattle Seahawks</A>\n";
or better yet, when you get into larger blocks you're going to love qq, which spans multiple lines and will correctly include any characters EXCEPT the delimiter
print qq¦
<A
HREF="http://www.example.com">Seattle
Seahawks</A>
¦;
where ¦ can be any character that is NOT in the string anywhere
print qq^<A HREF="http://www.example.com">Seattle Seahawks</A>\n^;
but () is also legal
print qq(<A HREF="http://www.example.com">Seattle Seahawks</A>\n);