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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing variables to a script

Status
Not open for further replies.
There are 2 ways. One by using the CGI.pm or the other one is by using the $ENV{'QUERY_STRING'}.

(1)

#!/usr/bin/perl -w

use CGI qw:)all);

print header;

$username = param('username');

Now you can access the variable by doing the following:

script.cgi?username=yourname.

(2)

#!/usr/bin/perl -w

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

$query = $ENV{'QUERY_STRING'};

if ($query =~m/variable/) {
print "Welcome to section 1";
exit;
}else{
print "Query String Error";
exit;
}


There is no Knowledge, That is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing.
-Aaron
 
sorry forgot to mention that im trying to send this variable back to the same script
 
AaronGeorge: you forgot about the POST method. It puts the values in STDIN where you have to read them.

jimmy: if you're calling the program from itself, there are several ways to pass parameters. If you make the part of the program you want to call again a subroutine, you can just call it recursively and pass the parameter in the usual way. If you're calling it via a command line call, you can pass the parameter in the command line and get at it using the ARGV array. You can also call it using the "do" command and pass the value via a global variable. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Tracy, I think jimmy is just trying to POST(or link?) back into the same script - I was trying to get jimmy to tell us exactly what method he is using(POST, GET, ?) to direct the script back into itself, and also what method he is using in script.pl to recognize incoming parameters. I don't think he's actually trying to recursively call the same script, or subroutine within the same script. Maybe I'm wrong?
Hardy Merrill
Mission Critical Linux, Inc.
 
Thanks tsdragon, I forgot about the form parsing. There is no Knowledge, That is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing.
-Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top