Skip to content

Perl

Perl is a general-purpose, dynamic programming language that supports both procedural and object-oriented programming. It was originally developed for text manipulation, but is now used for a wider range of tasks.

Perl is available as a module on Apocrita.

Usage

To run the default installed version of Perl, simply load the perl module:

module load perl

then run Perl with a script file:

perl example.pl

Installing Perl modules

You can use the "bootstrapping" technique to install the Perl local::lib package from Comprehensive Perl Archive Network (CPAN), and then self-install Perl modules into the local library.

To install local::lib, first load a Perl module and run the following command:

cpan -i local::lib

If this is the first time launching cpan, follow the interactive prompts. We do not recommend adding the proposed environment variables into your ~/.bashrc file. Instead, once the initial CPAN setup has completed, you can run the following command to activate your local library and set all the required environment variables:

eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"

To install Perl modules (for example Sort::Versions), use the following command after loading a Perl module and activating your local library:

cpan -i Sort::Versions

Ensure the eval command shown above is included in your job script if using a local library.

Example jobs

Serial jobs

Here is an example job running on 1 core with 1GB RAM:

#!/bin/bash
#SBATCH -n 1               # (or --ntasks=1) Request 1 core
#SBATCH --mem-per-cpu=1G   # Request 1GB RAM per core
#SBATCH -t 1:0:0           # Request 1 hour runtime

module load perl

perl example.pl

Here is an example job running on 1 core with 1GB RAM, using the Sort::Versions Perl module defined in the Perl code:

#!/bin/bash
#SBATCH -n 1               # (or --ntasks=1) Request 1 core
#SBATCH --mem-per-cpu=1G   # Request 1GB RAM per core
#SBATCH -t 1:0:0           # Request 1 hour runtime

module load perl

eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"
perl example.pl

References