#!/usr/bin/perl # This counter is used to build an array: $ctr=0; if ($ENV{REQUEST_METHOD} eq 'GET' && $ENV{QUERY_STRING} ne '') { #Test for GET method, etc $rawdata = $ENV{QUERY_STRING}; @array = (split("&", $ENV{QUERY_STRING})); } if ($ENV{REQUEST_METHOD} eq 'POST') { #Test for POST method. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); $rawdata = $buffer; @array = (split("&", $buffer)); } # This next block of code parses and "unstrings" the form data which the browser has encoded, # placing each name=value pair in the next array element (the array is @inputs.) foreach $widget (@array) { if ($widget =~ /(.*)=(.*)/) { ($key, $value) = ($1, $2); $value =~ s/\+/ /g; $value =~ s/%(..)/pack('c',hex($1))/eg; $inputs[$ctr] = $key . " = " . $value; $ctr++; } } #This final section just uses the "HERE DOCUMENT" Perl mechanism to generate # the required HTTP header lines (note the blank line) followed by a # few lines of HTML to begin the web page. print <<"EOF"; Content-type: text/html