|Think about Loose Coupling|
How to pass form data from a CGI script to its child process?by Nocturnus (Beadle)
|on Aug 25, 2012 at 09:08 UTC||Need Help??|
Nocturnus has asked for the wisdom of the Perl Monks concerning the following question:
I am developing a server-driven web application; the structure is the the typical one: A user enters data into a form, and after submission of the form, a CGI script on the server processes the form data. The webserver is Apache 2.x; the CGI script is written in Perl and uses the CGI module to extract the form data. This is working so far.
Let's call the CGI script described above ScriptA.pl.
Now, there is a second CGI script (ScriptB.pl). ScriptB.pl serves two purposes:
1) Like ScriptA.pl, it is called directly from the user's browser and processes form data (it also uses CGI.pm for doing that).
2) Under certain circumstances, it will be called by ScriptA.pl (using "system", "exec" or one of their friends), i.e. there is the following "call chain": User's browser with form ---> ScriptA.pl (via CGI) ---> ScriptB.pl.
I have the following problem: If ScriptB.pl is called from ScriptA.pl, ScriptB.pl must have access to all form data which originally is sent from the user's browser to ScriptA.pl, i.e. the form data must be passed somehow from ScriptA.pl to ScriptB.pl. I have no clue if there is a reasonable way to do that. So far, the following (idiotic) solutions have come to my mind:
- ScriptA.pl might transform the form data into command line parameters which are passed to ScriptB.pl when calling it. This has two serious disadvantages: I surely would have to write code which encodes the form data for the command line (all character sequences which might be treated specially by the shell would have to be transformed), and the form data might be very long, even longer than the maximum length which is allowed for a command line.
- ScriptA.pl might write the form data to a temporary file which is then read by ScriptB.pl. This is very costly (isn't it?), and ScriptB.pl still would have to be told the name of the temporary file.
What do you think about that problem?
Thank you very much,