Perl

From ScientificComputing
Jump to: navigation, search

Category

Development, Scripting, Perl

Description

Perl 5 is a highly capable, feature-rich programming language with over 29 years of development. Perl 5 runs on over 100 platforms from portables to mainframes and is suitable for both rapid prototyping and large scale development projects.

Available versions

Legacy versions Supported versions New versions
5.16.3, 5.24.1

Environment modules

Version Module load command Additional modules loaded automatically
5.16.3 module load new gcc/4.8.2 perl/5.16.3
5.24.1 module load new gcc/4.8.2 perl/5.24.1

Interactive session

Unlike Python and Java, Perl does not provide an interactive console. But it is possible to execute Perl command in your shell. For running the command print "Hello\n" in a shell, you need to call perl -e.
[leonhard@euler05 ~]$ module load new gcc/4.8.2 perl/5.16.3
Now run 'perl-init' to initialize your environment for Perl
[leonhard@euler05 ~]$ perl-init
[leonhard@euler05 ~]$ perl -e 'print "Hello\n";' 
Hello
[leonhard@euler05 ~]$
There are some additional Perl packages, which provide an interactive Perl console, but they are not fully supported on our clusters.

How to submit a job

You can submit a Perl job (my_perl_script.pl) in batch mode with the following command:
bsub [LSF options] "perl my_perl_script.pl"

Here you need to replace [LSF options] with LSF parameters for the resource requirements of the job. Please find a documentation about the parameters of bsub on the wiki page about the batch system.

If you specify the Perl interpreter on the first line of your script, then please use

#!/usr/bin/env perl

instead of

#!/usr/bin/perl

Otherwise the Perl interpreter from the operating system will be called when you directly execute the script with

./my_perl_script.pl

instead of

perl ./my_perl_script.pl
The Perl interpreter from the operating system is older and does not have the additional packages installed.

Example

As an example for a Perl job, we are looking at a script, that prints all environment variables for the current shell.
[leonhard@euler04 ~]$ cat test.pl 
#!/usr/bin/env perl

# This script prints out all environment varibles of the current shell.
my @keys = keys(%ENV);
while(my $key = shift @keys) {
        print "$key=$ENV{$key}\n";
}
[leonhard@euler04 ~]$ module load new gcc/4.8.2 perl/5.16.3
Now run 'perl-init' to initialize your environment for Perl
[leonhard@euler04 ~]$ perl-init
[leonhard@euler04 ~]$ bsub -n 1 -W 0:30 -R "rusage[mem=10]" perl test.pl   
Generic job.
Job <30746346> is submitted to queue <normal.4h>.
[leonhard@euler04 ~]$ bjobs
JOBID      USER        STAT  QUEUE      FROM_HOST   EXEC_HOST   JOB_NAME   SUBMIT_TIME
30746346   leonhard    PEND  normal.4h  euler04                 *l test.pl Oct 27 12:33
[leonhard@euler04 ~]$ bjobs
JOBID      USER        STAT  QUEUE      FROM_HOST   EXEC_HOST   JOB_NAME   SUBMIT_TIME
30746346   leonhard    RUN   normal.4h  euler04     e1243       *python.py Oct 27 12:35
[leonhard@euler04 ~]$ bjobs
No unfinished job found
[leonhard@euler04 ~]$ grep PERL lsf.o30746346 
PERLBREW_MANPATH=/cluster/apps/perl5/perls/perl-5.16.3/man
PERLBREW_VERSION=0.73
PERLBREW_PATH=/cluster/apps/perl5/bin:/cluster/apps/perl5/perls/perl-5.16.3/bin
PERLBREW_ROOT=/cluster/apps/perl5
PERLBREW_PERL=perl-5.16.3
PERLBREW_BASHRC_VERSION=0.73
The output of the Perl script is written to the lsf.o30746346 file.

Extensions

Perl is a highly extensible programming language. We provide a centrally installed package repository with provides you a large number of Perl packages. There is also the possibility to extend this even further by locally installing additional packages using cpanm in combination with local::lib, but this is not yet fully supported on Euler. But you are free to test it out yourself.

License information

GPLv3 or later

Links

https://www.perl.org

https://en.wikipedia.org/wiki/Perl