#!/usr/bin/perl # This program accepts input from STDIN and # writes it out to a data file called dataOut.dat # which is in the same directory as this perl code #open up file dataOut.dat, in same directory # open to append, file should exist and be writable if(-e "dataOut.dat") { open(OUTFILE, ">>dataOut.dat"); print "Opened file for append "; } #The POST method sends the form information # to the STDIN. The ammount of information sent # is given by the CONTENT_LENGTH element of the # %ENV the environmental variable associative array read(STDIN,$temp,$ENV{'CONTENT_LENGTH'}); #Expect that the input is sent to the program #as a single string, where we have separated #individual pieces of information by & #EACH individual piece of information is formated # as follows: # name_of_information = value_of_information #Split the input to seperate all of the Value Pairs # each pair = {Name, Value} @pairs = split(/&/,$temp); #print 2 blank lines to file print OUTFILE "\n\n"; #Process each pair to clean up all the funky # +,=, etc. symbols inserted into the information. # Recall + is used to represent spaces, = separates # elements of the Pair {Name=Value} foreach $item (@pairs) { ($key, $content) = split(/=/,$item,2); $content =~ tr/+/ /; $content =~ s/%(..)/pack("c",hex($1))/ge; #now you are ready to print out the value #of the current content to the output file print OUTFILE "$key : $content \n"; } #close the output file close(OUTFILE); print "Content-type: text/plain\n\n"; print "Thank you for your input"; #exit the program exit 0;