Using the Perl Definition Type
Perl is a widely used, multi-platform scripting language. Redwood Server includes two Perl definition types, one of which uses unicode UTF-8 encoding for the source.
note
You must assign at least one process server to run PERL process definitions in order to use the definition type.
A Perl interpreter needs to be installed on the system that the platform agent runs on. On UNIX systems it should be installed as /usr/bin/perl
. On Microsoft Windows systems the Perl interpreter will be found via the %PATH%
environment variable. For the Perl process definitions type to work properly the version should be 5.8.2 or higher.
Interpreter
By default, the interpreter for PERL scripts defaults to /usr/bin/perl -w
. You can override this by specifying an interpreter on process server-level with the LocalInterpreter_PERL
or LocalInterpreter_PERLUNICODE
process server parameter, like /usr/local/bin/perl -w
, for example. You can also specify a list of allowed interpreters on process server-level using the InterpreterWhitelist_PERL
or InterpreterWhitelist_PERLUNICODE
process server parameter and override the default interpreter on process definition-level with the parameter JCS_INTERPRETER_PERL
. Simply create the parameter and point it to your preferred interpreter, it must exist and be white-listed using the InterpreterWhitelist_PERL
process server parameter.
The InterpreterWhitelist_PERL
process server parameter takes a regular expression that must match the value of the JCS_INTERPRETER_PERL
parameter.
Variables and Parameters
- Parameters to the script are manipulated in the PERL source simply as if they are variables, using the standard
$PARAMETER
syntax. - Perl is a weak type-casted language; it only supports a single scalar data type: scalar. This maps directly for strings and numbers, but dates are subject to format conversions; see Scripting Date Formats.
- Out parameters are supported. Set the variable using any Perl method. For example a simple assignment in Perl is
$PARAMETER = VALUE
;. - Array parameters are supported provided your PERL interpreter supports arrays
Returning an Error
If your script code exits with a non-zero exit code this is correctly reflected in the server. Note that the maximum value that can be returned is operating system dependent; we recommend not relying on more than one byte (0..255).
Perl Examples
The following shows how to use a built-in and an environment variable as well as parameter:
print "Hello from " . $^O . "!\n"; # built-in variable
print "OS user = " . $ENV{USER} . "\n"; # environment variable
print "Your message was " . $message . "\n"; # parameter
Match one variable to a pattern, the following process definition needs two string parameters defined: str and pattern.
if ($str =~ m/$pattern/)
{
print "Match $i& found!\n";
}
else
{
die "$str does not match $pattern...\n";
}
The following example shows you how to return a non-zero exit code resulting in the process going into Error:
{
$N = 1;
print "Exiting with exitcode $N.\n";
return $N;
print "Not reached.\n";
}