I have a cgi script which takes few parameter like below.
testScript.cgi?arg=1&arg2=SomeThingElse&arg3=otherThing.....
The above script works well and perfectly.
Now I have another perl cgi script called mySecondScript.cgi
. It does its own thing but I want to call textScript.cgi
with arguments which are calculated in this script. How do I do that. Any elegant solution will be appreciated.
There are several ways of calling a "system call" from inside of an perl script. That might be any shell operation or even another perl script. My favorite is qx/[command]/
Look at this mini example to see how it works
pwd is a shell command, as would be in your case eg
This way you can even tunnel the results from the inner script to the outer script. Other ways could be backticks or the "system" command, but qx ist my personal favorite.
You probably want to use LWP::Simple to call the second program. Inside mySecondScript.cgi you would need something like this:
This will return the output from the CGI program (i.e. the HTML page that it generates). If you want more control over what you get back, then you need to use LWP::UserAgent.
$resp
will be an HTTP::Response object.Alternatively, if both of your program are running locally, it might be more convenient to refactor the important bits of testScript.cgi into a module that you can just load and use within mySecondScript.cgi.