Sample1.cgi simply invokes Sample1.pl. Here is its contents:

____________________________________________________________
#!/bin/sh

perl Sample1.pl
____________________________________________________________




Sample1.pl interprets the user's responses and generates a new HTML document.

____________________________________________________________
#
# Sample1.pl
#
# By Danny Swarzman
# Stow Lake Software
# 1998
# all lights observed
#
# This program processes the the user's responses
# to the form in Sample1.html
# The form has two fields, Name and Answer.
#
# This program appends the values of both fields
# to the file, responses.txt.
#
# This program sends a response to the user - either
# congratulations or sorry.
#
# *************
# main program
#
# *************
#
# Because this script is being called with a 
# POST method, get the name/value list from 
# standard input.

$rawQuery = ;

# Make a copy of the list.
# The copy will be cleaned up. 
# Keep the original for debugging.

$cleanQuery = $rawQuery;

# In a query string, characters can be represented
# by a percent sign followed by hex digits.
# Such escape sequences need to be converted 
# by changing the percent to backslash followed
# by the hex digits.

$backX = '\\x'; # The first '\' is to escape the second '\'
$cleanQuery =~ 
	s/%(\w\w)/eval('"'.$backX.$1.'"')/eg; # % becomes \x;
	
# Now change every plus sign to a blank.

$cleanQuery =~
	s/\+/\x20/g;		# + becomes blank

# Now we have a string like:
# 	Answer=5&Name=Fred Jones
#
# It's a list of name/value pairs separated by '&'
# Now create an array of which each element is
# a name/value pair
#
 
@separatedPairs = split ( /&/, $cleanQuery );

# Each element of separatedPairs is a string
# representaing a name/value pair like:
# Answer=5

# Now construct a dictionary so that 
# the rest of the program can extract
# named fields as needed.

# Of course when there only two 
# specific fields in which we are interested,
# the code could simply look for those names
# but this is a more general approach.
#

@accuredList = ();

# Break down each name/value pair and put its parts into
# accrued list which will form the dictionary.

foreach $separatePair ( @separatedPairs )
{
	@brokenPair = split ( /=/, $separatePair );
	if ( scalar ( @brokenPair ) < 2 )
	{
		@brokenPair[1] = "";
	}
	@accruedList = ( @accruedList, @brokenPair );
}
%dictionary = @accruedList;

# We look up the data in which we're interested.

$Name = $dictionary{"Name"};
$Answer = $dictionary{"Answer"};

# Print the mime header followed by
# the HTML header and some debugging stuff.
print <
Sample1 Test Results



Debugging Info: The user's response to Sample1.html was delivered to the Sample1.cgi as query string $rawQuery.

The user's name is: $Name
The answer is: $Answer

EndOfPrelude # Present results according to user's responses. if ( $Name ) { &SaveResponses; print < EndOfThanks if ( $Answer == 4 ) { print < EndOfGood } else { print < Bitter luck next time.
EndOfBad } } else { print < EndOfNoName } print ""; # ************* # Subroutine # # ************* sub SaveResponses { } ____________________________________________________________