In the script to be called, wrap as much as you can, save for printing the HTTP header, into a subroutine, call it body() for example This should be a unique function name. In that script file, your main routine should be something like:
use strict;
use CGI;
my $cgi = new CGI;
print $cgi->header();
body();
1;
sub body {
...
}
If you are comfortable with it, it's probably better to make this a small module at this point, though in some situations I don't think that is necessary.
In the script that you want to call this, simply now "include 'file.pl';" at the top, where file.pl is the script above, and where you want to include the output from that script, you can use "body();" there. Of course, if you make it a module, you'll need to do some other things.
There's a few little gotchas with variable inclusion and the like, but that's the general idea.
And if this body() will change directories, you can easily get the current working directory at the start of the sub, then restore that when you are done with the processing.
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.