Perl 5 [1] is a highly capable, feature-rich programming language with over 27 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.
Installed Versions
Perl is available as part of the operating system. More recent versions are available through the module system.
[hpc6 ~]$ which perl
/usr/bin/perl # path to system perl
[hpc6 ~]$ module avail perl
---------------- /usr/local/easybuild_allnodes/modules/all ------------
BioPerl/1.7.8-GCCcore-12.2.0 Perl/5.32.0-GCCcore-10.2.0 Perl/5.34.1-GCCcore-11.3.0
Perl/5.30.0-GCCcore-8.3.0-minimal Perl/5.32.1-GCCcore-10.3.0-minimal Perl/5.36.0-GCCcore-12.2.0
Perl/5.30.0-GCCcore-8.3.0 Perl/5.32.1-GCCcore-10.3.0 Perl/5.36.0-GCCcore-12.3.0
Perl/5.30.2-GCCcore-9.3.0-minimal Perl/5.34.0-GCCcore-11.2.0-minimal Perl/5.36.1-GCCcore-12.3.0
Perl/5.30.2-GCCcore-9.3.0 Perl/5.34.0-GCCcore-11.2.0 Perl/5.38.0-GCCcore-13.2.0 (D)
Perl/5.32.0-GCCcore-10.2.0-minimal Perl/5.34.1-GCCcore-11.3.0-minimal
[hpc6 ~]$ module load Perl/5.38.0
[hpc6 ~]$ which perl
/usr/local/easybuild_allnodes/software/Perl/5.38.0-GCCcore-13.2.0/bin/perl
Running Perl in HPC
Request a compute node
[mrd20@hpc5 ~]$ salloc -c 3 --mem=12GB -t 30:00
salloc: Granted job allocation 2161742
salloc: Waiting for resource configuration
salloc: Nodes compt237 are ready for job
[mrd20@hpc5 ~] ssh compt237
[mrd20@compt237]
Command Prompt:
[mrd20@compt237] module load Perl/5.38.0-GCCcore-13.2.0
[mrd20@compt237] perl -del
DB<1> print "hello y'all"
hello y'all
DB<2> q
Command Line:
Check if GD Module is installed. If not available, it will throw "Can't locate <module>.pm in @INC ..."
[mrd20@compt237] perl -e "use GD"
Run the perl script:
create a file "hello.pl" with a following content:
print("Greeting is Hello, world\n");
Execute
[mrd20@compt237] perl hello.pl
output:
Greeting is Hello, world
References:
[1] Perl Home
The process is similar to Configure-Make-MakeInstall as described in the section above. The version of perl can be different so change the download link and version accordingly.
wget http://www.cpan.org/src/5.0/perl-5.38.0.tar.gz
tar -xzf perl-5.38.0.tar.gz
cd perl-5.38.0
./Configure -des -Dprefix=$HOME/<perl-directory>
make
make test
make install
(Note: It is a capital C in Configure)
Add the following lines in your .bashrc file as mentioned in the section above.
PATH=$PATH:/home/<CaseID>/perl/5.38.0/bin
PERL5LIB=$PATH:/home/<CaseID>/perl/5.38.0/lib
Even if using the system perl, $PERL5LIB needs to be managed to reflect these local modules
Modules may installed in your home directory tree to extend the local perl install capabilities. We have found the following modifications to be useful. Be sure to update/export the $PERL5LIB environment variable to reflect the installed location of these modules.
The key is establishing the PREFIX value in the .cpan configuration file. The first time that you use cpan on the cluster, it creates the ~/.cpan/CPAN directory, and that's all that lines 2 and 3 above accomplish. If you've already used cpan, and have ~/.cpan in your /home, then install the modules via cpan should work fine without any elevated privileges.
Summary of commands:
export PERL5OPT="-I${HOME}/.usr/local/perl/lib/perl5 -I${HOME}/.usr/local/perl/lib/perl5/site_perl"
cpan # enter yes at auto config prompt
exit # exit cpan shell
vi .cpan/CPAN/MyConfig.pm # edit line 'makepl_arg' => q[] to 'makepl_arg' => q[PREFIX=~/.usr/local/perl],
cpan
install JSON # Enter "y" at the warning
Configuration details are found in ~/.cpan/CPAN/MyConfig.pm
When this file is first generated, it holds paths consistent with the active shell environment. When building local modules, it's important to update the configuration file to reflect the version of perl to be used with the local modules. Manual edits of ../MyConfig.pm or updates from within cpan will work:
perl -MCPAN -e shell
cpan> o config makepl_arg=/home/<caseid>/.usr/local/perl
Perl is available through the standard module system, in the default module path.
module load Perl/5.38.0-GCCcore-13.2.0
else confirm that you are using the system perl:
[hpc5 ~]$ which perl
/usr/bin/perl
[hpc5 ~]$ perl -v
This is perl 5, version 26, subversion 3 (v5.26.3) built for x86_64-linux....
Install the Perl module:
Call the CPAN with a right version of perl
perl<version> -MCPAN -e shell
Install the required module
>install <Module>[::<SUBMODULE]
For an example, to install the Statistics moudle, Multtest, it is install Statistics::Multtest.
If the installation does not go through, install the modules manually as showed:
perl<version> Makefile.PL PREFIX=$HOME/<perl-directory>; make; make test; make install
If the tests are failing and need to force install
>force install <Module>[::<SUBMODULE]
wget -O- http://cpanmin.us | perl - -l ~/perl5 App::cpanminus local::lib
eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`
echo 'eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`' >> ~/.bash_profile
echo 'export MANPATH=$HOME/perl5/man:$MANPATH' >> ~/.bash_profile
Install modules
cpanm Module::Name