separator

Take a quiz or make one of your own

This code will read input sent to your program from either a posted form or by using the get method.


#!/usr/local/bin/perl

my($bfr, $nm, $vl);
if($ENV{'REQUEST_METHOD'} eq 'POST') {read(STDIN, $bfr, $ENV{'CONTENT_LENGTH'})}
else {$bfr = $ENV{'QUERY_STRING'}}
for(split /&/, $bfr) {
s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
tr/+/ /;
($nm, $vl) = split(/=/, $_);
$Input->{$nm} = $vl
}

__END__

Take note that input can contain HTML tagging, so a safer method is presented on the next page.

Reading Input to the Program/A Safer Version/Using CGI.pm to Read Input

separator

© thecgibin.com