Using the Perl Definition Type
RunMyJobs supports two Perl Definition Types, one of which uses UTF-8 encoding for the source code.
Note: To use this Definition Type, you must assign at least one Process Server to run Perl Process Definitions.
A Perl interpreter needs to be installed on the system where the Platform Agent runs. 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 (for example, /usr/local/bin/perl -w
) at the Process Server level with the LocalInterpreter_PERL
or LocalInterpreter_PERLUNICODE
Process Server parameter. You can also specify a list of allowed interpreters at the Process Server level using the InterpreterWhitelist_PERL
or InterpreterWhitelist_PERLUNICODE
Process Server parameter, and override the default interpreter at the Process Definition level with the parameter JCS_INTERPRETER_PERL
. The interpreter must 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
You can manipulate parameters in a Perl script like regular 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. For more information, see Scripting Date Formats.
You can set an Out parameter using any Perl method. For example, a simple assignment in Perl is $PARAMETER = VALUE;
.
Array parameters are supported provided your Perl interpreter supports arrays. Arrays must have unique elements.
Returning an Error
If your script code exits with a non-zero exit code, this is correctly reflected in RunMyJobs. Note that the maximum value that can be returned depends on the operating system. Redwood recommends not relying on more than one byte (0-255).
Perl Examples
This example 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
This example shows how to match one variable to a pattern. The Process Definition must have two string parameters defined: str
and pattern
.
if ($str =~ m/$pattern/)
{
print "Match $i& found!\n";
}
else
{
die "$str does not match $pattern...\n";
}
This example shows how to return a non-zero exit code, resulting in the process going into Error status.
{
$N = 1;
print "Exiting with exitcode $N.\n";
return $N;
print "Not reached.\n";
}