<!-- SophiaKnows -->

PERL PARSEFORM
Rev 2: December 2004

#!/usr/local/bin/perl

# This subroutine returns key value pairs submitted to the
# script via standard HTTP post/get methods


sub Parse_Form {
   if ($ENV{'REQUEST_METHOD'} eq 'GET') {
      @pairs = split(/&/, $ENV{'QUERY_STRING'});
   } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
      read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
      @pairs = split(/&/, $buffer);
      
      if ($ENV{'QUERY_STRING'}) {
         @getpairs =split(/&/, $ENV{'QUERY_STRING'});
         push(@pairs,@getpairs);
         }
   } else {
      print "Content-type: text/html\n\n";
      print "<p>Use Post or Get";
   }

   foreach $pair (@pairs) {
      ($key, $value) = split (/=/, $pair);
      $key =~ tr/+/ /;
      $key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
      $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   
      $value =~s///g;
   
      if ($formdata{$key}) {
         $formdata{$key} .= ", $value";
      } else {
         $formdata{$key} = $value;
         push(@keylist,$key);
      }
   }
}   
1;

< CODEBASE | TOP^ | MAINPAGE >

Text & Design By Tony Pisarra
© SophiaKnows 1998-2004