#!/usr/bin/perl

print "Content-type: text/html\n\n";       # header info for HTTP

$buffer = <>;				   # form input from STDIN
@pairs = split(/&/, $buffer);              # fields are extracted

foreach $pair (@pairs)			   # input for each field is processed
  {
    $pair =~ tr/+/ /;                      # decoding: + -> blank
    ($name, $value) = split(/=/, $pair);   # field name and value separated
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/chr(hex($1))/ge; # %nn -> characted
    $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/chr(hex($1))/ge;

    # input is stored into associative array %in:

    if (defined ($in{$name})) {		   # checkboxes may produce
      $in{$name} .= "\0";		   # multiple values for a field:
    }					   # separated with \0.
    $in{$name} .= $value;
  }
    
# printing a HTML document:
   
print <<THANKYOU;
<html>
<head>
<title>Thank you</title>
</head>
<body>
  <h2>Thank you!</h2>
  <br>
  <h3>You supplied the following information:</h3>
THANKYOU

print "\n<ul>";

while (($name, $value) = each(%in)) {        # the input values are printed
#  if ($name ne "submit") {		     # submit could be ignored
    print "<li>$name:\t$value </li>";
#  }
}
print "</ul>";

print <<DOCEND;
</body>
</html>

DOCEND