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

Ok ... without swamping everyone with code

Snippet from first script

($percent_alpha) =CalculatePercentage($alpha, $totalresidues);
This variable is calculated using a subroutine in the first script, so is generated within the program, rather than being inputted into it via say a form.

I now want to pass the variable $percentage_alpha to another CGI script for further processing. So ... basically passing from one CGI script to another.

Does that make sense?

Replies are listed 'Best First'.
Re^2: another CGI question ... passing values to another script
by theorbtwo (Prior) on Jun 08, 2005 at 18:17 UTC

    You want one script to output HTML, such that when a user does something, the value the first script computed will be passed on to the second script?

    If so, you can do two different things, depending on what "does something" means. If you want the user to fill out another form, and hit the submit button again, then use an input tag, with it's type attribute set to hidden -- the HTML spec has details.


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Re^2: another CGI question ... passing values to another script
by CountZero (Bishop) on Jun 08, 2005 at 19:57 UTC
    The term "CGI Script" is not a well defined concept it seems.

    All it means is that it is a "script" which implements the Common Gateway Interface, being a protocol about passing data about the information request from the server to the script. This can be done through environment variables (the "GET" mode) or through STDIN (the "POST" mode) or through the command line (the "ISINDEX" mode). STDOUT is used for returning info from the script to the server (which might relay it to the client -- although that falls outside of the CGI protocol).

    So the only way you can speak to a CGI script (which can be written in any language) is through "GET" or "POST" (we forget conveniently about the ISINDEX command line mode). Any other way of speaking to the "CGI script" (e.g. calling it directly as a subroutine or module or ...) does not use it as a CGI script but as a Perl, PHP, VB, ... program and will have to follow the rules for calling such programs. So strictly speaking there is no way under the CGI protocol to call a subroutine which lives in another CGI script. CGI scripts are, seen from the server, monolithic; they have one entry point, get their input from "GET" or "POST" and return their data through STDOUT. Whether the CGI script is one bunch of spagetti code or consists of 1,000 subroutines in 100 modules, is totally transparent for the caller. Unfortunately for your purpose it is also opaque: you can't see or access its parts separately.

    So if you want to call another CGI script from within a CGI script you must launch a new request to the server (modules like LWP or WWW::Mechanize spring to mind). Still you will only be able to call this other CGI script as a whole.

    If however you just want to call a subroutine which resides in another script or module or program, this has nothing to do with CGI at all and it is in no way different from useing, requireing or doing a subroutine in such used, required or done script, module or program (see use, require, do), provided of course these scripts, ... reside on the same server, are written in Perl and you have the necessary privileges to access them.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law