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 Job Server to run Perl Job 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 Windows systems the Perl interpreter will be found via the %PATH%
environment variable. For the Perl Job 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 Job Server level with the LocalInterpreter_PERL
or LocalInterpreter_PERLUNICODE
Job Server parameter. You can also specify a list of allowed interpreters at the Job Server level using the InterpreterWhitelist_PERL
or InterpreterWhitelist_PERLUNICODE
Job Server parameter, and override the default interpreter at the Job Definition level with the parameter JCS_INTERPRETER_PERL
. The interpreter must be white-listed using the InterpreterWhitelist_PERL
Job Server parameter.
The InterpreterWhitelist_PERL
Job 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 a 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 Job 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";
}