LPM: ATP (All Terrain Perl)

Joe Hourcle oneiros at dcr.net
Thu Apr 20 09:36:33 CDT 2000



On Wed, 19 Apr 2000, David Hempy wrote:

> To determine if I am running as CGI, I just look at $ENV{REMOTE_ADDR}.  
> (Any cgi-specific environment variable will do.)  If it is true, all I
> do in this script is blurt out a Content-type line and
> "<HTML><BODY><PRE>".  From there, my command-line intended print
> statements work just fine in the browser with no modification.

Although it doesn't quite apply in your case (as you're giving it a
<TITLE> and some HTML at the bottom to close <PRE> and let the person go
back), some people something like this may want to just send:

	Content-type: text/plain\n\n

(which any intelligent browser will accept as being a plain text file, and
not try to format it, which is good if you're dumping massive files this
way)

of course, it's still good to put some sort of an 'end marker' just to let
the person know that you've finished.

> Another nifty trick for a cgi script is setting $|=1;  This turns
> buffering off and makes your web page print to the browser in real
> time, instead of spitting out the entire web page after the job has
> completed.  This looks more like the paced output we're used to seeing
> at the command line.  Great for tasks that more than a second or two
> so you're not staring at the "Loading" animation wondering if your
> script is really doing anything.

if you're using an older server, you may have to make sure that the CGI
starts with 'nph-' (so the server doesn't decide to buffer it).  Recent
versions of apache don't do it, but I can't remember when they made that
change.  (I can't remember how netscape server behaves, and have no clue
as to IIS)

-----
Joe Hourcle




More information about the Lexington-pm mailing list