Perl/mod perl

From Devpit
Jump to: navigation, search
  • It's infeasible not to use use strict under mod_perl. This is because global variables don't disappear when your program ends, and may mess up future execution of scripts, causing intermittent problems.

Convenient template for writing stand-alone mod_perl programs:


use strict;
use warnings;

my $r = shift;

eval {
	local $ENV{PATH} = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
	my $iparams = [$r->method eq 'POST' ? $r->content : $r->args];
	push @$iparams, undef if @$iparams % 2;  # Ensure even number of elements
	$iparams = {@$iparams};
	my $oparams = {};

	## Put your code here
	## It's okay to die here


	## Print your output here

if($@) {
	warn "$0 died:  ", $@;
	print $@;