Shows the



When I go into public_html, I see the following:



Now I am going to run super.html in Netscape. This example was taken from the CGI/Perl text by Zak that we are using in the course.



When I click on submit, you will see that it executes super1.cgi.



I am now going to show the views of super.html and super1.cgi to show what was actually executed. Again, let me note that this example was taken from the text used in the course: CGI/Perl by Zak (Course Technologies). First I will show the code in super.html:






<H1>Super Bowl Survey Form</H1>




<P><B>What did you think of the Super Bowl game?</B><BR>

<INPUT TYPE=radio NAME=Game VALUE=0> It was a great game.<BR>

<INPUT TYPE=radio NAME=Game VALUE=1> It was a boring game.<BR>

<INPUT TYPE=radio NAME=Game VALUE=2> I didn't watch the game.</P>


<P><B>Vote for your favorite Super Bowl commercial:</B><BR>

<INPUT TYPE=radio NAME=Commercial VALUE=Budweiser> Budweiser<BR>

<INPUT TYPE=radio NAME=Commercial VALUE=FedEx> FedEx<BR>

<INPUT TYPE=radio NAME=Commercial VALUE=MasterCard> MasterCard<BR>

<INPUT TYPE=radio NAME=Commercial VALUE=Pepsi> Pepsi</P>


<INPUT TYPE=submit VALUE="Submit Survey">





Next I will show the code in super1.cgi:



#super.cgi - saves form data to a file, and creates a dynamic

#Web page that displays a message and survey statistics

print "Content-type: text/html\n\n";

use CGI qw(:standard);

use strict;


#declare variables

my ($game, $commercial, @records);

my @game_count = (0, 0, 0);

my %comm_count = ("Budweiser", 0,

"FedEx", 0,

"MasterCard", 0,

"Pepsi", 0);


#assign input items to variables

$game = param('Game');

$commercial = param('Commercial');


#save form data to a file

open(OUTFILE, ">>", "survey.txt")

or die "Error opening survey.txt. $!, stopped";

print OUTFILE "$game,$commercial\n";



#calculate survey statistics

open(INFILE, "<", "survey.txt");

@records = <INFILE>;


foreach my $rec (@records) {


($game, $commercial) = split(/,/, $rec);

$game_count[$game] = $game_count[$game] + 1;

$comm_count{$commercial} = $comm_count{$commercial} + 1;



#generate HTML acknowledgment


print "<BODY>\n";

print "<H2>Thank you for participating in our survey.</H2>\n";


print "<EM><B>What did you think of the Super Bowl game?</EM></B>\n";

print "<TABLE>\n";

print "<TR><TD>It was a great game.</TD> <TD>$game_count[0]</TD></TR>\n";

print "<TR><TD>It was a boring game.</TD> <TD>$game_count[1]</TD></TR>\n";

print "<TR><TD>I didn't watch the game.</TD><TD>$game_count[2]</TD></TR>\n";

print "</TABLE><BR>\n";


print "<EM><B>Vote for your favorite Super Bowl commercial:</EM></B>\n";

print "<TABLE>\n";

foreach my $key ("Budweiser", "FedEx", "MasterCard", "Pepsi") {

print "<TR><TD>$key</TD> <TD>$comm_count{$key}</TD></TR>\n";


print "</TABLE>\n";

print "</BODY></HTML>\n";


Please note that when the cgi was put out on the web, the attributes needed to be set.






Once I have Commands/Advanced commands/Change File Attributes, I make the following changes.