Skip navigation.
Your source for Perl tips, howto's, faq and tutorials

specify a minimum module version

( categories: )

Sometimes you must use a specific module version in your programs. To avod using earlier version of that module, append the minimum version number you want in the use 'module' statement:


#-- Use version 5.8 of later of module LWP
use LWP 5.8

Your program will exit with an appropriate error message if the installed module version is lower than the version you specified

execute commands on remote machines using ssh

( categories: | )

You can execute commands on remote machines from a Perl script using the Net::SSH::Perl module.

This module allows you to execute a command remotely and receive the STDOUT, STDERR, and exit status of that remote command.

One big advantage of Net::SSH::Perl over other methods is that you can automate the login process, that way you can write fully automated perl scripts, no console interaction is required in order to authenticate in the remote machine.


list the installed modules

( categories: | )

There are several ways to obtain the list of perl modules installed in a system:

-- Using perldoc

There are 2 commands, depending of the kind of perl module:

perldoc perlmodlib

'perldoc perlmodlib' list the modules that come preinstalled with the standard perl package.

perldoc perllocal

'perldoc perllocal' lists the optional modules that are installed in your system that don't come with perl by default.

This command returns lots of useful information for every optional module installed, like the installation date, the directory where the module was installed, the module version number, etc.

extending the library path

( categories: | )

By default perl looks for modules in the standard library path and the current directory. Sometimes you need to use some modules that are installed in non standard locations; there are several ways to deal with this situation:

-- Install the module somewhere in the standard library path

If you have administrator privileges, then the best solution is to install the modules in any of the system defined library paths (you can get the paths executing perl -le 'print foreach @INC').

-- Set the environment variable PERL5LIB

Perl will look for modules in the directories specified in PERL5LIB environment variable before looking in the standard library and current directory, so you can set this variable to locate your modules.

check the version of installed modules

( categories: | )

To check the version number of a module use the following one-liner: 'perl -M -e 'print "$<module>::VERSION \n"'.


#-- check the version number of CGI module
perl -MCGI -e 'print "$CGI::VERSION \n"'

list the directories where perl modules are located

( categories: | )

The array @INC contains the list of places that the 'do EXPR', 'require', or 'use' constructs look for their library files. The following one-liner shows the contents of that array:

perl -e 'foreach $folder (@INC) { print "$folder\n";}'

useful modules to develop web related applications

( categories: | )

General purpose module for creating web pages

- Template
Template Toolkit - excellent template system used primarily for generating dynamic web content

Very useful to fetch web contents

- WWW::Mechanize
Very helpful module to automate interaction with a website

get module information

( categories: | )


There are 2 ways to get the information:

perldoc module
Example: perldoc CGI


man module
Example: man Mail::Send



If you want to have a look at both the documentation and source code of a module, run the following:

perldoc -m module
Example: perldoc -m IO::Dir



perldoc -l module
Example: perldoc -l Catalyst

check if a module is installed

( categories: | )

Let's say that you want to know whether module Tie::Hash is installed. To find out, execute the following from the command line:

perl -MTie::Hash -e 1

If you don't get any output from the above command then the module is installed; if you get an error, it's not installed

Syndicate content