in reply to another CGI question ... passing values to another script

The simplest thing would be to use system or one of its variants (backticks, exec, etc.). E.g. if your other CGI script is called foo.pl and it's implemented with CGI:

my $cgi_script = 'foo.pl'; my @args = qw( bar=baz quux=frobozz ); system( $cgi_script, @args ) == 0 or die "call to $cgi_script failed: $?";

But I think this is a fragile design. A better alternative would be to refactor the functionality of the script that you want to call into a function, and define a module around this function that the first script can load (with use or require or do). And once you do this refactoring, what used to be the "second" CGI script in this story would become a wrapper around the core module. You'd ultimately end up with two CGI scripts calling the same module.

Update: Modified the example code to more closely resemble an interaction with another CGI script, implemented using CGI (thanks to BUU for pointing out the omission of CGI.pm). Added explanatory remarks.

the lowliest monk

Replies are listed 'Best First'.
Re^2: another CGI question ... passing values to another script
by BUU (Prior) on Jun 08, 2005 at 18:47 UTC
    Just to nitpick a tad, your example will only work if $cgi_script is a perl module using the CGI module (or perhaps some other library that implements CGI's non-standard debugging input). CGI scripts don't read *any* arguments from ARGV, they read from $ENV{QUERY_STRING} for GET type requests and STDIN for POST type requests.

    So if you really wanted to use system, you would probably want something like:
    #assuming $cgi_script and @args $ENV{QUERY_STRING}=join'&',@args; my $resp = `$cgi_script`;
Re^2: another CGI question ... passing values to another script
by Angharad (Pilgrim) on Jun 08, 2005 at 17:45 UTC
    Thanks. I'll try that