#!/usr/bin/perl

#This tells the server where to find the Perl program to run the script.
#Every time you see an '#' you know that this is a comment. Perl will not read this as script.

 

#This tells the user's browser that the script will be sending back a Web page:
print "Content-type: text/html\n\n";

 

#This takes the input from the user (STDIN) and puts it into a variable (buffer)
#within the server's environment:
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

 

#This takes any return characters off the end of the line that comes across from the Web:
chomp $buffer;

 

#This splits up (on the "&") the input from the user into pairs and puts this information in a variable (@pairs)
@pairs = split(/&/, $buffer);

 

#This takes each pair (each group it got when it divided the whole line on the "&") and splits it further:
foreach $pair (@pairs){
($name, $value) = split(/=/, $pair);

 

#This translates all the characters so that they are not returned to the user
#as unreadable text with invisible characters, etc.:
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

 

#This associates each input type (or form element), by name, with the value of that input element:
if ($FORM{$name}) {
$FORM{$name} = "$FORM{$name}, $value";
}
else {
$FORM{$name} = $value;
}
}

 

#This tells the user's Web browser how to make the page look that is returned to the user:
#Instead of this syntax (in green) you may use individual print statements for each line of code with quotes and followed by semicolon.
#(Example: print "<html>.........;")
print <<END_of_html;
<HTML>
<HEAD><TITLE>Reply from Server</TITLE></HEAD>
<BODY bgcolor=#ffffff>
<H2 ALIGN=center>Here's the reply from the server:</H2>
Thank you, <B>$FORM{name}</B>. You picked <B>$FORM{choice}</B><P>
Here is what you have to say: <B>$FORM{comment}</B>
</BODY>
</HTML>
END_of_html

 

END OF SCRIPT >>NOTE: make sure you hit a carraige return (new line) after the last "END_of_html"<<do not copy this line



#Below is a way to see all the form elements and their values. This part is not necessary for the above script:
#foreach $key (keys(%FORM))
#{print "<P><B>KEY:</B> $key .....<B>VALUE:</B> $FORM{$key}";
#}