|
|
|
CGI
Read Input
#!/usr/local/bin/perl
#
# Subroutine &read_input takes and decodes data either
from
# QUERY_STRING (for GET method, default) or STDIN (for POST
method)
# Returned is an associative array of names and values.
CODE |
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;
}
|
Tutorial By Xtasy
|
|