docs.roxen.comView this page in a printer friendly mode
DocsRoxen2.1Programmer ManualPerl
Copyright © 2001, Roxen Internet Software
Suggestions, comments & compliments
manuals@roxen.com
 DEMO  DOCS  PIKE
 COMMUNITY  DOWNLOAD
www.roxen.com

   

Using In-Line Perl Code
Running Perl Scripts
Supported mod_perl API Methods

Running Perl Scripts

With the "Script output" option of the perl support module set to HTTP, it is possible to run old perl CGI scripts more or less as they are, only with better performance, provided they don't rely on their environment being reset upon each run of the script. (This performance boost comes in part from the script already being loaded and compiled, thus staying resident in-between requests and in part from the fact that there is no need to fork off new processes for the script.)

The environment variables are the same as those available in standard CGI, plus those added by roxen for your convenience.

As with CGI, anything you print to STDERR ends up in the server's general debug log file (or the console, in the event of your starting the server with the --once flag).

CGI-Style Scripts

A simple example of a traditional CGI script in perl could look like:


#! /usr/local/bin/perl
print "Content-type: text/plain\r\n\r\n";
print "Environment variables:\n";
for (sort keys %ENV)
{
  print $_, "=", $ENV{$_}, "\n";
}

mod_perl-style Scripts

Turning this one into a mod_perl-style script, also runnable by the Perl support module and by some considered a bit tidier, might result in something along the lines of:


my $r = Roxen->request();
$r->print("Content-type: text/plain\r\n\r\n");
$r->print("Environment variables:\n");
for (sort keys %ENV)
{
  $r->print($_, "=", $ENV{$_}, "\n");
}