Perl

Installing Perl modules – a reminder

October 3rd, 2007

The simplest way to install a Perl module is to use the Perl CPAN module. Of course you have to install this first. Once you have you can do perl -MCPAN -e 'install Collection::Module'

For example: perl -MCPAN -e 'install Magic::Invisibility'

If the module isn't available for installation this way, but a package is available for download at the CPAN Web site, or elsewhere, you can usually install it the manual way. For example, following my recent post about a login banner, I recently installed the Text::Banner module on a Linux server as follows:

wget http://search.cpan.org/CPAN/authors/id/L/LO/LORY/Text-Banner-1.00.tar.gz
gunzip Text*gz
tar xvf Text*tar
cd Banner
cat README

... [I read the README file at this point]

perl Makefile.PL
make
make test
make install
perl -MText::Banner -e 1

[no error message means it was installed successfully]

For more detail (including details of how to install into a non-standard location) see:

http://search.cpan.org/~jhi/perl-5.8.0/pod/perlmodinstall.pod

 


UPDATE (13/10/2007):

I always used to use the  perl -MCollection::Module -e 1 way of checking whether a module was installed. Another, in some ways better, way to check is to print the version number of a module. To do this enter the command:

perl -e "use Collection::Module; print $Collection::Module::VERSION";

For example:

perl -e "use SOAP::Lite; print $SOAP::Lite::VERSION";

If the module is installed, this either prints the version number or, if the module hasn't been built to report its version, a blank line.

If the module is not installed, you get a "Can't locate ..." error message.

Leave a comment

 

Check whether a Perl module is installed

August 16th, 2005

To check whether a Perl module is installed, use the command:

perl -M<module>

For example:
perl -MCGI

or:

perl -M<module>::<module>::<module>

For example:
perl -MIO::Socket::UNIX

If perl returns a scree of stuff beginning "Can't locate...", then the module isn't installed.

If all you get is a new line, the module is installed - in which case press Ctrl+D to get back to the command prompt.

Leave a comment



Perl Coding Standards

August 12th, 2004

A colleague pointed out this page:

www.bbc.co.uk/guidelines/webdev/AppA.Perl_Coding_Standards.htm

This is a set of Perl coding guidelines for developers working for the BBC. Most of what's in it is straightforward good sense. One thing I hadn't come across, and hadn't considered before is flagged up by the following paragraph:

"You MUST NOT put markup language in code. CPAN provides several good templating modules, and a stripped-down version of an HTML::Template (called BBC::CGI::Template) can also be used. There should not be any situation where you need to put HTML or other markup into Perl code."

This caused me to go away and look at the HTML::Template module. I use HTML in my Perl CGI scripts all the time. Using templates seems like a much better idea and I intend to start using templates from now on.

Leave a comment



Introductions to Perl

June 28th, 2004

I came across an excellent, gentle introduction to the basics of the Perl programming language at:

www.cs.rpi.edu/~hollingd/eiw/notes/PerlIntro/PerlIntro.html

However, for anyone considering dabbling in Perl (or making a career out of it), the standard and best starter book on Perl is:

Programming Perl by Larry Wall, Tom Christiansen and Randal Schwartz.

Chapter 1 of this book – where Larry Wall explains the basics of Perl by drawing comparison to the syntax of spoken language – is still my favourite piece of computer literature. I read it on a flight from Edinburgh to London, years ago, and I remember being utterly bowled over by the clarity of the explanation. I consider that chapter a masterpiece of computer writing because it's clear, witty, easy to read and I don't think it could have been written any better.

Another useful book, and another one that pretty much every Perl programmer has read, is:

Learning Perl by Randal Schwartz, Tom Christiansen and Larry Wall.

Potentially similar posts

Leave a comment



Which Perl modules are installed

June 13th, 2004

You want to use a Perl module in a script you are writing. How do you know if it's already installed? Your first stop is to the perlmodinstall man page. At a command prompt, type:

man perlmodinstall

Alternatively, you can look up once of the many HTML versions of this man page (or any other man page) on the Internet. For example:
www.hmug.org/man/1/perlmodinstall.html

The man page tells you what you need to know:

First, are you sure that the module isn't already on your system? Try "perl -MFoo -e 1". (Replace "Foo" with the name of the module; for instance, "perl -MCGI::Carp -e 1".

If you don't see an error message, you have the module. (If you do see an error message, it's still possible you have the module, but that it's not in your path, which you can display with "perl -e "print qq(@INC)"".)

Leave a comment



^ back to top ^

Page 2 of 3123