GET and POST for Perl

This is a Perl script I wrote a while back for collecting GET and POST variables.

use CGI;
$query = new CGI;

#GET variables
@values = split(/&/,$ENV{'QUERY_STRING'});
foreach $i (@values) {
  ($varname, $mydata) = split(/=/,$i);
  $queryGET{$varname} = $mydata;
}

#POST variables
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@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;
  $queryFORM{$name} = $value;
}

#ENCTYPE variables
foreach $key (sort {$a <=> $b} $query->param()) {
  next if ($key =~ /^\s*$/);
  next if ($query->param($key) =~ /^\s*$/);
  if ($key !~ /^file-to-upload-(\d+)$/) {
   $queryFORM{$key} = $query->param($key);
   next;
  }
}
Written by: Dag Jonny Nedrelid
©2007-2012 http://thronic.com


Feel free to leave a comment.
Name:
URL:
0