#!/usr/local/bin/perl # # CGI script to access text area using &read_input # print "Content-type: text/html
I read with interest your review. It said:
"; %incoming = &read_input; # Read information into associated # array %incoming. $your_text = $incoming{'review'}; # Fetch the text from the array. print $your_text; # Print the text. print "I think you're wrong, but you're entitled to your opinion, I suppose. "; # Main body of program ends here sub read_input { local ($buffer, @pairs, $pair, $name, $value, %FORM); # Read in text $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; } # Split information into name/value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%(..)/pack("C", hex($1))/eg; $FORM{$name} = $value; } %FORM; }