Perl

De Wiki de Calcul Québec
Aller à : Navigation, rechercher
Cette page est une traduction de la page Perl et la traduction est complétée à 100 % et à jour.

Autres langues :anglais 100% • ‎français 100%

Sommaire

Description

Perl is a free programming language which is interpreted and has acquired a vast library of contributed packages over the 25+ years of its existence. Its strengths are manipulating strings, database access and its portability (according to this article). Its weaknesses are its poor performance and the ease with which one can write obscure and illegible code. By design, Perl offers several different ways of accomplishing the same task. Many programmers have adopted this language and write code that is very compact but difficult to decipher.

Loading the Interpreter

Perl is a language which installed by default on Calcul Québec's servers and it's therefore generally unnecessary to load a module in order to use it.

Installing Packages

A large number of Perl packages can be installed by means of the Comprehensive Perl Archive Network, by using the tool cpan. The instructions vary according to the version of Perl which is installed.

Initial Configuration for Perl 5.10 (Colosse, Helios, Briarée, Hadès, Mp2)

During the first execution of the command cpan the utility will ask you if you want to allow it to configure the majority of settings automatically. Respond yes.

[name@server $] cpan
 
...

Would you like me to configure as much as possible automatically? [yes]
...


Afterwards, use the following commands to change your installation directory:

 
 > o conf mbuildpl_arg "--install_base ~/perl/"
 > o conf makepl_arg "PREFIX=~/perl/"
 > o conf commit
 > exit
 


Note that it is important to quit cpan at this stage and to restart it so that the new settings are used.

Initial Configuration for Perl 5.8 (Cottos, Ms2, Psi)

During the first execution of the command clan the default option is to perform a manual configuration. You can choose "no" to allow the configuration to be done automatically.


[name@server $] cpan
 
...
If you do not want to enter a dialog now, you can answer 'no' to this
question and I'll try to autoconfigure. (Note: you can revisit this
dialog anytime later by typing 'o conf init' at the cpan prompt.)

Are you ready for manual configuration? [yes] no
...


Next, use the following commands to change your installation directory:

 
 > o conf mbuildpl_arg "--install_base ~/perl/"
 > o conf makepl_arg "PREFIX=~/perl/"
 > o conf commit "/home/user/.cpan/CPAN/MyConfig.pm"
 > exit
 


where you should replace user by your username. Note that it is important to quit cpan at this stage and restart it so that the new settings are used.

Package Installation

When the initial configuration is done, you can install any of the more than 25,000 packages available on CPAN. For example:

[name@server $] cpan
 
cpan shell -- CPAN exploration and modules installation (v1.7602)
ReadLine support available (try 'install Bundle::CPAN')

cpan> install PerlIO::gzip
...
Running install for module PerlIO::gzip
Running make for N/NW/NWCLARK/PerlIO-gzip-0.18.tar.gz
Fetching with LWP:
  ftp://CPAN.mirror.rafal.ca/pub/CPAN/authors/id/N/NW/NWCLARK/PerlIO-gzip-0.18.tar.gz
CPAN: Digest::MD5 loaded ok
Fetching with LWP:
  ftp://CPAN.mirror.rafal.ca/pub/CPAN/authors/id/N/NW/NWCLARK/CHECKSUMS
...

CPAN.pm: Going to build N/NW/NWCLARK/PerlIO-gzip-0.18.tar.gz

Checking if your kit is complete...
Looks good
Writing Makefile for PerlIO::gzip
...
Running make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/read.....ok
t/write....ok
All tests successful.
Files=2, Tests=561,  0 wallclock secs ( 0.37 cusr +  0.05 csys =  0.42 CPU)
...
Running make install
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree


Lastly, you must add the path of your installation directory to your environment. You can do this by adding the following line to your .bashrc:

[name@server $] export PERL5LIB=$HOME/perl/lib64/perl5:$HOME/perl/share/perl5


(assuming that you have installed the packages in the directory $HOME/perl).

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Ressources de Calcul Québec
Outils
Partager