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


In reply to Re^2: another CGI question ... passing values to another script by CountZero
in thread another CGI question ... passing values to another script by Angharad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.