Home Technical Articles Perl Modules ..

Perl Modules ..

by SupportPRO Admin

PERL MODULES

What is Perl?

Perl is a high-level programming language with an eclectic heritage written by Larry Wall and a cast of thousands. It derives from the ubiquitous C programming language and to a lesser extent from sed, awk, the Unix shell, and at least a dozen other tools and languages. Perls process, file, and text manipulation facilities make it particularly well-suited for tasks involving quick prototyping, system utilities, software tools, system management tasks, database access, graphical programming, networking, and world wide web programming. These strengths make it especially popular with system administrators and CGI script authors, but mathematicians, geneticists, journalists, and even managers also use Perl.

A Perl module is a discrete component of software for the Perl programming language. Technically, it is a particular set of conventions for using Perls package mechanism that has become universally adopted. A module defines its source code to be in a package (much like a Java package), the Perl mechanism for defining namespaces, e.g. CGI or Net::FTP or XML::Parser; the file structure mirrors the namespace structure (e.g. the source code for Net::FTP is in Net/FTP.pm). Furthermore, a module is the Perl equivalent of the class when object-oriented programming is employed.

An Example

sub hello { Hello, world!\n }

print hello();

How do I install Perl using the source code?

To build Perl you need a C compilation environment. After downloading the source code and opening it up, you should first read the INSTALL document which will detail how to build Perl on most systems. There are a number of README for platforms where special care is needed in building Perl. As always, reading the documentation is a Good Thing.

Perl can be installed using the standard source code distribution on almost all platforms Perl runs on. This includes all the UNIXes (and good lookalikes, meaning POSIX environments like OS/2, Plan 9, QNX, Amiga, MPE/iX, VMS, OS390, Stratus VOS), and Microsoft platforms. The most notable exceptions are (as of 1999-Mar-24).

MacOS (1)

AS/400 (2)

Novell Netware (2)

The Basics of Module Installation

Most modules are available from CPAN – the Comprehensive Perl Archive Network. They are supplied in what is known as a tarball. A tarball is a gzip compressed tar file. When a module is made the directory structure it lives in is converted to a single file that contains both the files and the directory information. A program called tar performs this function and the resultant file is called a tar file. Tar files have a .tar file extension. This tar file is then compressed using the gzip (GNU Zip) program. Gzipped files have a .gz extension thus a standard module will be called something like:

Some-Module-0.01.tar.gz

The first part is the name, the next part the version number and the last part the .tar.gz extension signifying that this is a tarball. You uncompress a tarball using the tar program like this.

tar -zxvf Some-Module-0.01.tar.gz

Installing Perl modules

Perl modules may be installed using the CPAN module or from source.

CPAN method

perl -MCPAN -e shell (to get an interactive CPAN shell)

perl -MCPAN -e install Time::JulianDay (if you know the name of the module, you can install it directly without interacting with the CPAN shell)

Within the CPAN shell:

i /expression/ will search for a Perl module containing expression, and

install module will install the module.

Manual installation

To manually install a Perl module:

1. Download the Perl module from CPAN or other site.

2. Extract the tarball.

3. Run perl Makefile.PL

4. Run make

5. Run make test

6. Run make install

Checking for existence of a Perl module

An easy way to check for the existence of a Perl module on your system is to run perl -e use module;

Example:

perl -e use HTML::Parser;

If nothing is returned, Perl was able to locate the module. Otherwise, you will see Cant locate HTML/Parser.pm in @INC.

recompile

recompile() is a very special command in that it takes no argument and runs the make/test/install cycle with brute force over all installed dynamically loadable extensions (aka XS modules) with force in effect. The primary purpose of this command is to finish a network installation. Imagine, you have a common source tree for two different architectures. You decide to do a completely independent fresh installation. You start on one architecture with the help of a Bundle file produced earlier. CPAN installs the whole Bundle for you, but when you try to repeat the job on the second architecture, CPAN responds with a Foo up to date message for all modules. So you invoke CPANs recompile on the second architecture and youre done.

Another popular use for recompile is to act as a rescue in case your perl breaks binary compatibility. If one of the modules that CPAN uses is in turn depending on binary compatibility (so you cannot run CPAN commands), then you should try the CPAN::Nox module for recovery.

UPGRADING PERL MODULE

Download the file from

www.cpan.org

untargzip the archive

cd into directory

Compile and install the package:

perl Makefile.PL

Make

Make install

Article Authored by Anand Gopal

Author, Anand Gopal, is a Systems Engineer with SupportPRO. Anand specializes in Level 1 and Level 2 Linux / Windows Administration. SupportPRO offers 24X7 technical support services to Web hosting companies and service providers.

If you require help, contact SupportPRO Server Admin

Server not running properly? Get A FREE Server Checkup By Expert Server Admins - $125 Value

Leave a Comment