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!

Is it possible to call one CGI script from another? 2

Status
Not open for further replies.

MissouriTiger

Programmer
Oct 10, 2000
185
US
I'm developing an online forum. I'm using multiple scripts, rather than cramming all the code into one script.

Is it possible for one script to call another, and pass data to it? If so, can you show me an example?

Also, I search and search, but cannot find very much good CGI info on the Web, regarding more advanced topics. Most of what I find is either extremely basic introductory stuff, or lots of "tutorials" which are all copied from the same source (what source I'm not sure). I mean, their examples are all the same, and they even use the same variable names. Where can I find some good advanced CGI stuff?

I even tried the Perldoc, but the explanations assume you are a C programmer or something, which I am not. It took me 2 days just to figure out how to return multiple arrays from a procedure and dereference them. The Perldoc only confused me. Hey, should I submit a FAQ on it?

Any and all advice is welcome,

--Greg Norris _______________________________________
Constructed from 100% recycled electrons
 
If I understand the question, you are trying to post
CGI parms from one piece of code to another piece of
CGI code.

The following piece of code 'POST's some CGI parms
to the second peice of code which writes them to a
file.

Code:
#!/usr/local/bin/perl
use strict;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new(env_proxy => 1,
                              keep_alive => 1,
                              timeout => 30,
                            );	
$ua->post('[URL unfurl="true"]http://your_server.com/cgi-bin/LWP/catch.cgi',[/URL]
	[
	first 	=> 'john',
	last	=> 'smith',
	year	=> '1963'
	]);


This would live at and would catch and write the CGI parms to disk,
Code:
#!/usr/local/bin/perl
use strict;
use CGI;
my $o = new CGI;
open(OPF,">post_out.txt") or die "Failed to open OPF, $!\n";
my $first = $o->param('first');
my $last = $o->param('last');
my $birth = $o->param('year');
print OPF "FIRST: $first LAST: $last YEAR: $birth\n";
close OPF;
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
No, I have written a program, an online forum like this one, and I am using multiple scripts, instead of pili8ng all the code into a single script.

I just wanted to have the scripts interact with one another, call functions from each other.

Now I know how, but the compiler is squawking about the following:

use strict;

require db_functions.cgi;

Compiler says I can't use barewords. I searched through 3 perl books & none of them bother to discuss this stuff.

I found the following tek-tips thread (thread219-129163), in which Tracy Dryden explains it.

I think I need to put the file name in quotes. I'll try it and see.
_______________________________________
Constructed from 100% recycled electrons
 
Actually, goBoating, I relaize now I may need to do something like what you showed me. I haven't had time to get that far yet, though.

There might be a point in my app when one script performs some processing, then it passes the data to a different script, which returns a dynamic page to the user. When this happens, the first script will be finished, so the program will not flow back to the first script, but will end with the second script. I'm not absolutely sure I'll go this route.

I'm keeping all html generating procedures in one cgi file, all db stuff in another, all string functions in another, and all validation in another. I'm also writing my subs to be as generic as possible, so that my code is extensible to future projects.

The actual flow of the program is controlled by another set of scripts, such as login.cgi, add_user.cgi, etc., which just basically call the functions from the other files as needed, passing parameters to them. So far I'm just calling subs.

I will have to research the LWP module. I've not seen that user agent stuff before.

Thanks a lot for your help,

Greg _______________________________________
constructed from 100% recycled electrons
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top