CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Passing Variables to a script

 



andy7t
User

Jan 4, 2005, 11:17 AM

Post #1 of 4 (905 views)
Passing Variables to a script Can't Post

Hi,

This should be a straight forward question.

I want to pass variables from one Perl script to another.

I've tried this:


SCRIPT 1:

$calling=`perl script2.cgi var1=thing`;

SCRIPT 2:

use CGI;

$query=new CGI;

$called=$query->param('var1');



However, $called never returns anything. If i just run perl script2.cgi var1=thing direct from the command line, SCRIPT 2 works fine, so why doesn't EITHER the CGI module pick up the paramaters, or SCRIPT 1 doesn't pass the paramaters?


I know that the script is been called sucessfully, because $calling returns the rest of SCRIPT 2, it just doesn't pass the vars.


(This post was edited by andy7t on Jan 4, 2005, 11:18 AM)


kencl
User

Jan 12, 2005, 2:27 PM

Post #2 of 4 (889 views)
Re: [andy7t] Passing Variables to a script [In reply to] Can't Post

try: $calling=`perl script2.cgi?var1=thing`;

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!


davorg
Thaumaturge / Moderator

Jan 13, 2005, 5:03 AM

Post #3 of 4 (886 views)
Re: [kencl] Passing Variables to a script [In reply to] Can't Post


In Reply To
try: $calling=`perl script2.cgi?var1=thing`;


Did you try it?


Code
$ cat script2.cgi 
#!/usr/bin/perl

print "This is script2\n";
$ cat test.pl
#!/usr/bin/perl

$calling = `perl script2.cgi?var1=thing`;

$ ./test.pl
Can't open perl script "script2.cgi?var1=thing": No such file or directory
$


The correct answer is to get the arguments from @ARGV. script2.cgi is (despite it's name), _not_ being called as a CGI program and therefore you can't use CGI-style parameter passing.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


kencl
User

Jan 13, 2005, 6:26 AM

Post #4 of 4 (885 views)
Re: [davorg] Passing Variables to a script [In reply to] Can't Post

I didn't try it no. I never used the command line. My assumption was that he wanted to run it in a CGI environment and was just testing with the command line.

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives