#!/usr/bin/perl
print "Content-Type: text/html\n\n";
# Print HTML header
print <
formDataSave.cgi
EOHH
# Get the request method
$reqMeth = $ENV{"REQUEST_METHOD"};
# Open the file to which to save the form data
open(FD, ">form.data") || print "Error opening \"form.data\"
\n";
print "Form Data: ";
if ($reqMeth eq "GET") {
# If the method is "GET", the data is in the REQUEST_METHOD
# environment variable
print $ENV{"QUERY_STRING"};
print FD $ENV{"QUERY_STRING"};
} elsif ($reqMeth eq "POST") {
# If the method is "POST", the data is one line on standard input
$line = ;
print $line;
print FD $line;
} else {
# Otherwise, we don't know.
print "Cannot determine form data method
\n";
} # end if-elsif-else
# Close the file
close FD;
# Print the HTML footer
print <
EOHF
# Done