> >
> > I am trying to learn PERL and decipher some code somone else wrote. I have
> > the code snip -- $ENV{'QUERY_STRING'} --
> > I have not found this in the archives, so I am hoping someone will answer
> > this:
> >
> > I cannot figure out exaclty what the ENV is.The book says it contains the
> > current environment. OK, but what is in this environment. I can't find info
> > what the environment consists of. What does the 'Query_String' mean?
> >

While ENV contains a lot of stuff, as everyone has already pointed out, 
this particular key (QUERY_STRING) is specific to cgi -- that is, a program 
to be used on a server.  $ENV{QUERY_STRING} contains the string that is 
sent when a user clicks the submit button on a form in a web page, when the 
form's method parameter is set to "get".  If you have a form:
<form action="http://mydomain.com/cgi-bin/test.cgi"; method="get">
         <input type=text name="Input" value="My Value">
         <input type=submit value="Submit">
</form>

and you hit submit on it (assuming you have the cgi script that follows in 
your cgi-bin on your server, and that you change "mydomain.com" to the 
correct address to your domain) you can pick up the value of the input text 
field.

here's the perl that would pick that up -- I know, I should be using CGI.pm :)

#!/usr/bin/perl -w

use strict;

print "Content-Type: text/html\n\n";

print $ENV{QUERY_STRING}; # prints out 'Input=My%20Value'

# or you can print out the whole ENV hash

print "$_: $ENV{$_}<br>" foreach keys %ENV;


Hope that helps
Aaron Craig
Programming
iSoftitler.com

Reply via email to