Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I access parameters passed to a perl CGI script? 1

Status
Not open for further replies.

lotsToLearn

Programmer
Jun 10, 1999
9
CA
Hi support world. <br>
<br>
I am passing a string of parameters to a Perl CGI script but I do not know how to access them in the Perl script. I thought that I could use @ARGV but that doesn't work. <br>
<br>
I realize that this is a no brainer to answer but I am new to web programming and could use some help. <br>
<br>
Thanks for the tip.<br>
<br>
lotsToLearn
 
Well; I'm new to Perl too; but in disecing a script that I got free off the 'net I found the following line repeated often for finding info that I was told in the readme to include in the paramaters (be sure to use "method=post" in your &lt;form&gt; tag when using this line):<br>
<br>
$Whatever = $fields{'Whatever'}<br>
<br>
I'll admit, I did "doctor" this a little (for ease of use) but I don't THINK I messed anything up :)<br>
<br>
Please let me know how this works for you.<br>
<br>
<br>
-Robherc<br>
robherc@netzero.net
 
You must first determine whether you're going to send the data as GET or POST. This is determined in the HTML. GET sends as a command line argument, and POST as an environment string. POST is generally the better choice, since there is virtually no limit to the amount of data you can send, and it does not appear in the Location bar on the browser.<br>
<br>
To actually pick up the string, use something like this (for POST data):<br>
<br>
read(STDIN, $InputData, $Length);<br>
<br>
The data will be placed in the $InputData variable, and the length of the string will be identified with $Length.<br>
<br>
Hope this helps.<br>
<br>
-- Heidi
 
Hi,<br>
<br>
Just a quick tip and (hopefully helpful) suggestion:<br>
Use the CGI in perl!<br>
That way you can access the contents of a parameter like this:<br>
<br>
$name = param('name');<br>
<br>
which will take the parameter called "name" and assign its value to $name<br>
<br>
I find it very nice to work with! The documentation is fairly easy to read, too, with examples for follow.<br>
<br>
Cheers,<br>
Milamber
 
Milamber-<br>
<br>
The only problem with that being:<br>
a) You can only pass a VERY limited amount of data as parameters<br>
and<br>
b) The data is shown in the location bar (this can get EXTREMELY ugly)<br>
<br>
when using the POST method (i.e. &lt;form action=post"submissionURL" method=POST&gt;) you can access your information with ease via the<br>
$Whatever = $fields{'Whatever'}<br>
method with no difficulty & you can pass an unlimited amount of data with NO clutter in the location bar.<br>
<br>
<br>
-Robherc<br>
robherc@netzero.net
 
Robherc,<br>
The data is not displayed, in my experience, in the location bar, when using the CGI module.<br>
I believe it uses the POST method by default, so the same ease of use applies, with a simpler code structure.<br>
I've tried in both the win32 version and the Linux version of perl 5, and neither displayed the info in the location bar.<br>
To be honest, I don't know what (if any) the limit on the data is, but I assume it's identical to your POST method (because it *is* the POST method..)...<br>
<br>
Cheers,<br>
Milamber<br>

 
OK, sorry...I thought you were referring to using the GET method...actually, POST IS now the default...didn't quite understand what you meant.<br>
<br>
<br>
-Robherc<br>
robherc@netzero.net
 
Indeed. Look at Find the CGI.pm module. Install as you normally would a perl module: <br>
<br>
tar -zxvf whatever.tar.gz<br>
perl Makefile.PL<br>
make<br>
make test<br>
make install<br>
<br>
In the top of your script, put:<br>
<br>
use CGI;<br>
<br>
Then, when you're ready to harvest your POST'ed data, call the CGI module like:<br>
<br>
my $cgi = new CGI;<br>
my $first_param = $cgi-&gt;param('first_param');<br>
etc...<br>
<br>
In this example, one parameter passed to the script would be called "first_param" (i.e. &lt;INPUT NAME="first_param"...&gt; )<br>
<br>
This pretty much assumes you're using a Unix-alike system. I have no idea what state CGI.pm is in for Micros~1 machines, but it might be available.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top