Perl

From oldwiki.scinet.utoronto.ca
Jump to navigation Jump to search

Availability on SciNet systems

Perl is installed on both the GPC (version 5.10.1) and the TCS (version 5.8.8). While perl can be run without the need to load any software modules,some of perl's functionality (especially installing modules from CPAN) relies on the GNU c compiler, so if you use perl on the GPC you most likely want to load the gcc module first:

  module load gcc

Note: if, as we encourage, you use the intel compilers on the gpc as well, you should load the intel module after the gcc module to ensure that the environment variable are set properly.

Perl modules

One of the nice features of perl is the large number of perl modules that are out there. The Comprehensive Perl Archive Network (CPAN) is a large repository for these modules.

Note: perl modules are internal to perl are should not be confused with the software module system.

There are so many perl modules that we cannot possible maintain all of these. A number of module come with perl out-of-the-box and are therefore available. To find out what those are, you can use the command

$ perl -MFile::Find=find -MFile::Spec::Functions -Tlw -e 'find { wanted => sub { print canonpath $_ if /\.pm\z/ },no_chdir => 1 }, @INC'

Local perl modules from CPAN

Users are generally responsible for installing any other modules they need (although we can always help). This poses a slight hurdle, as CPAN's package system would try to install these in system directories to which users have no access. Fortunately, there is an easy way to setup CPAN to use a local folder for perl libraries.

In the following, the local directory for perl libraries will be assumed to be ~/perl5. For the most recent version of CPAN (which is required to install several modules and to use the local modules), follow the steps outlined below.

Modifications to .bashrc

A number of paths need to be set for perl to find the local modules you will install.

   export PERL_LOCAL_LIB_ROOT="$HOME/perl5"
   export PERL_MB_OPT="--install_base $HOME/perl5"
   export PERL_MM_OPT="INSTALL_BASE=$HOME/perl5"
   export PERL5LIB="$HOME/perl5/lib/perl5/x86_64-linux-thread-multi:$HOME/perl5/lib/perl5"
   export PATH="$HOME/perl5/bin:$PATH"

Setting up a user-space CPAN modules directory

The following only works for the GPC (for now).

1. First, since installing perl modules may involve compilation, be sure to be on a devel node (e.g. ssh gpc01). On the gpc, make sure that the gcc module is loaded (module load gcc).

2. If this is not your first time using CPAN (for instance, you have tried before using it and found that you could not install any packages), you may have to remove your ~/.cpan directory. This will trigger a new configuration in the next step.

3. Start a CPAN shell:

   $ cpan

4. It will ask if you would like to get as much as possible configured automatically/ Say no. (In older versions of perl, 5.8.8, it would ask you whether you are ready for a manual configuration, to which you'd say yes or <enter>).

5. It will now ask you a bunch of questions, almost all of which you can answer with the default (i.e. press <enter>), except for a few:

  • When the installation asks for Parameters for the 'perl Makefile.PL' command, enter:
    LIB=~/perl5/lib/perl5 INSTALLMAN1DIR=~/perl5/man/man1 INSTALLMAN3DIR=~/perl5/man/man3
    (all on one line).
  • When it asks for Parameters for the 'perl Build.PL' command, it is suggested not to add an '--install_base ' argument.
  • When it asks If no urllist has been chosen yet, would you prefer CPAN.pm to connect to the built-in default sites without asking? say yes.
  • When it asks for the repository to use, you can pick what you want, but after choosing 'North America' and 'Canada', I chose site #6, for no particular reason.
  • Warning messages regarding YAML and AddHistory should be harmless.

7. A module called local::lib is required to read the .bashrc environment variables properly. To install the latest local::lib , type install local::lib in the CPAN shell and press <enter>. If you are not sure it you should do this, do it anyways as it installs a bunch of modules that other modules you may be using likely depend on. Note: you may have to do a force install local::lib to avoid spurious test failures to spoil your installation.

8. As the module is installing, numerous prerequisites will also be installed (including an updated version of CPAN). Answer each with the default option.

9. Type exit into the cpan shell.

With version 5.8.8 (the version which we had with CentOS 5), this recipe would throw an error, and two more steps were required:

10. Restart the cpan shell. The shell will ask if you want to configure as much as possible automatically. Choose yes.
11. Install local::lib again as you did in step 7 and now everything should install without errors.

Installing CPAN modules

Either from the CPAN shell or from the command line, you can now install packages quite simly by perl -MCPAN -e install <perlmodule> or simply cpan <perlmodule>.

Using the modules

You can use local perl modules just as you would use system-wide perl modules.