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!

Calling one Perl CGI script from another

Status
Not open for further replies.

erulia

IS-IT--Management
Jan 29, 2003
20
US
I am writing a complicated set of Perl CGI scripts that work as follows:
Script 1: Contains a form in which users enter information.
Script 2: Gets the information from Script 1 and puts it in a database.
Script 3: Gets the information from the database and displays it in a web page.

I would like Script 2 to automatically call Script 3 when it is finished updating the database. How do I do this?

-Unix Sys Admin
 
This is more easily done with packages. I will explain that if you wish just let me know.

To call one perl script from another you can use the these command.

do
system
require
use
exec
fork

Which on you choose would depend on weather you need it to return or not an if parameters need to be passed.

I would just try to require the scripts methods and then use them directly

require 'some.pl';

method_inside_some();





haunter@battlestrata.com
 
How does this work in the CGI world? With these scripts, the output is sent to a web page. The "Script 2", as I described it, does not do any output, but needs to send the POST'ed data on to Script 3, which will then generate output.

-Unix Sys Admin
 
Unless you use the 'print' command. Noting is ever sent to the screen weather it is a command line script or a CGI script.

This is a simple app that can be combined into one script quite easily.

Let me illustrate a simple control script to handle everything.

You have the right idea, use and object oriented approach. This is what you are talking about. It will make you project much more scalable.

Example:
/usr/bin/perl -w
package CONTROLSCRIPT;

#Tell PERL where modules are
use lib ('/path/to/modules/', '/path/to/some/other/modules');

#get modules
use CGI;
require database_module;
require display_module;

#setup interfaces to modules
$CONTROLSCRIPT::OUTPUT = display_module->new();
my $QUERY = database_module->new();
my $cgi= new CGI;

#get contol parameter
my $action = $cgi->param('action');


if ($action eq ''){
#dump form to screen
print $CONTROLSCRIPT::OUTPUT->form();#call a method
} elsif ($action eq 'write_data'){
#execute command in another package
$QUERY->insert('somedata');
my $data = $QUERY->select('ID' => $id,
'WHERE'=> $where);
print $CONTROLSCRIPT::OUTPUT->results($data);
}
else{exit;}

#This is an example of using modules on and OOP manner
#the new() subroutines are:
sub new {
$pkg = shift;
$obj = {};
$obj = bless $obj, $pkg ;
return $obj;
}
#These are returning interface structure to your packages


haunter@battlestrata.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top