• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Parse a GET in perl5

I send from my compter a request
"http://www.dlrb.com/cgi-bin/aaa.cgi?iden="Bill Smith"
I know how to parse a POST header, but I think this would be a GET.  What is the code to parse the header in the unix cgi file to set a variable equal to "Bill Smith"?

1 Solution
Just place this sub at the bottom of your script and call it like this


before you will need any of the variables sent to the script.  It will parse for get or post and leave all the variables in a hash where the key is the varaibel name and the value is the value.  Your examole would become:

print $fields{'iden'}; #Prints "Bill Smith"

Notice the quotes!!!!  You don't need them (I think)

#---------------------------------Parse Input---------------------------------------#
#                  Arguments:      NONE                                                                                    #
#                  Purpose            Standard Form/Query String Parsing                                          #
#                  Calls:            NONE                                                                                    #

sub parseInput()
      #Parse form variables
      if ($ENV{'REQUEST_METHOD'} eq "POST")
            read(STDIN, $temp, $ENV{'CONTENT_LENGTH'});

      elsif ($ENV{'REQUEST_METHOD'} eq "GET" )
            $temp = $ENV{'QUERY_STRING'};

      foreach $item(@pairs)
            ($key,$content)=split (/=/,$item,2);
            $content=~tr/+/ /;
            $content=~ s/%(..)/pack("c",hex($1))/ge;

use CGI;
donb1Author Commented:

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now