#!/usr/bin/perl # Tom Blum # June 2007 # IWA-HWG Homework/ Instructor M. Kowalski #read in a string sent by the POST method of a calling page (week6_form.html) read(STDIN,$buffer, $ENV{'CONTENT_LENGTH'}); #$buffer variable to use for debugging purposes #$buffer="submit=Submit&Spec=Thomas+Blum&home=yes&capab=yes&internal=no&email=yes&connect=hspeed&hphone=999-999-9999"; #parse the $buffer variable and create a hash #the expected name-value pairs are: # submit Submit (from submit button input) # Spec StudentName (from select) # home Yes/No (from radio input) # capab Yes/No (from radio input) # internal Yes/No (from radio input) # email Yes/No (from radio input) # connect dialup, etc. (from radio input) # hphone 999-999-9999 (from text input) # @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } my($sec, $min, $hour, $day, $mon, $year, $wday, $yday, $isdst) = localtime; $year += 1900; $today = ($mon+1) . "/" . $day . "/" . $year; #open and select file to append data to $filename="student_log.csv"; open STUDENT_LOG, ">>" . $filename or die "Problem creating file: $!"; select STUDENT_LOG; #prepare line to add to data file $line = join ",", $today, $FORM{Spec}, $FORM{home}, $FORM{capab}, $FORM{internal}, $FORM{email}, $FORM{connect}, $FORM{hphone}; #write line to data file print "\n$line"; close STUDENT_LOG; select STDOUT; &start_html; &html_head("Week 6 Form Response"); #argument is title print "