Perl

From oldwiki.scinet.utoronto.ca
Revision as of 17:31, 26 November 2010 by Rzon (talk | contribs) (Created page with "==Availability on SciNet systems== Perl 5.8.8 is installed on both the GPC and the TCS. While perl can be run without the need to load any software modules, but some of perl's fu...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Availability on SciNet systems

Perl 5.8.8 is installed on both the GPC and the TCS. While perl can be run without the need to load any software modules, but 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 in your .bashrc:

  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 ~/myperl, but you could choose another folder as well.

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. Prepare your own perl module directory

   $ mkdir ~/myperl

3. 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.

4. Start a CPAN shell:

   $ cpan

5. It will ask you whether you are ready for a manual configuration. Say yes (or <enter>).

6. 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 one: When the installation asks for Parameters for the 'perl Makefile.PL' command, enter:

  PREFIX=~/myperl/ LIB=~/myperl/lib INSTALLMAN1DIR=~/myperl/man1 INSTALLMAN3DIR=~/myperl/man3

(all on one line).

7. When it asks for the repository to use, you can pick what you want. I chose #6, for no particular reason.

8. That should be it for cpan.

Modifications to .bashrc

A number of paths need to be set for perl to find the modules

   export PERL5LIB=~/myperl/lib64/perl5/site_perl:~/myperl/lib/perl5/site_perl/5.8.8
   export PATH=~/myperl/bin:$PATH

You could consider building your own software module for this.

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>.

It may be a good idea to install Bundle::CPAN at this point. Note that this will take a bit of time, during which you'l be pressing enter from time to time.

Using the modules

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