Handy Perl modules

This page is some recommendations about Perl modules for beginner programmers.

Install a module

You can usually install a Perl module by downloading it from a CPAN copy and then doing the following kind of thing:

tar xfz Example-Module-0.1.tar.gz
cd Example-Module
perl Makefile.PL
make test
make install
You can skip the "test" stage if the tests fail.

You can automatically install module dependencies using the cpan program which comes with Perl:

cpan Image::PNG
If the module doesn't install due to failing tests, you can use the -f option to install it anyway:
cpan -f XML::Parser
Despite what people will tell you, sometimes it really is necessary to do this.

Be aware of ...

The cpan program is fairly reliable, but it produces a lot of verbose output and nagging messages, so someone produced a simpler thing called cpanm installed via App::cpanminus which is simpler to use. There is also something called cpanplus in the standard Perl distribution, but this doesn't work very well, and is best avoided.

Create temporary files

File::Temp is a sensible way to do this.

Copy or move files

File::Copy is part of Perl itself and is the best way to do this.

Find files


Join the names of directories or folders together independent of operating system


Write a test for a module

If you need to write tests to ensure that your Perl module functions correctly, the first place to look is Test::More. You can probably ignore the advice in the module's documentation to start with Test::Simple. Also, ignore the Test module, which is superceded by Test::More.

Use templates to create something from data

If you need to create something like an HTML page from Perl data, the first thing to look at is Template. Whatever you do, don't use the HTML generation in the CGI module.

Write installer scripts for a Perl module

The most standard helper is ExtUtils::MakeMaker.

Beware of hype

The Module::Build module is hyped by a lot of Perl people, but for a beginner, it's extremely hard to use, since the module documentation is inadequate. You'll need to scrabble around looking for examples in other people's code if you use this, so avoid it.

Connect to an SQL database

If you want to connect to an SQL (standard query language, sometimes pronounced "sequel") database, the first thing to look at is DBI. Depending on what database you are using, you will also need to install a database driver. For example, for the MySQL database, you need to install DBD::mysql. For the SQLite database, you need to install DBD::SQLite.

Beware of old documentation

There are also a lot of other things called "database" modules which aren't SQL style databases, but are just ways of storing hash tables onto a disk. These tend to show up in older Perl documentation.

Make error messages

The Carp module is the best way to make error messages for a module which relate to the point of calling of the module, so you can find out what call caused problems, rather than giving a message from deep inside the module itself.

Parse HTML

Beware of hype

There are some cases where the most sensible thing to do is to parse HTML using regular expressions.

Find out where your executing file is

If you need to find out where the executing file is, use FindBin. The variable $FindBin::Bin tells you where the executable is.

You can find the location of a loaded library by looking at the @INC array.

Copyright © Ben Bullock 2009-2023. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer