[root@spam ~]# perldoc -m Mail::Send
specify a minimum module version
( categories: perl modules )
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:
Example:
#-- 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: system | perl modules )
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.
Example:
list the installed modules
( categories: installing modules | perl modules )
-- 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: command line parameters | perl modules )
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: one liners | perl modules )
To check the version number of a module use the following one-liner: 'perl -M -e 'print "$<module>::VERSION \n"'.
Example:
#-- check the version number of CGI module
perl -MCGI -e 'print "$CGI::VERSION \n"'
list the directories where perl modules are located
( categories: one liners | perl modules )
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: web | perl modules )
- CGI
General purpose module for creating web pages
General purpose module for creating web pages
- Template
Template Toolkit - excellent template system used primarily for generating dynamic web content
Template Toolkit - excellent template system used primarily for generating dynamic web content
- LWP
Very useful to fetch web contents
Very useful to fetch web contents
- WWW::Mechanize
Very helpful module to automate interaction with a website
Very helpful module to automate interaction with a website
get module information
( categories: getting help | perl modules )
-- READ MODULE DOCUMENTATION
There are 2 ways to get the information:
perldoc module
Example: perldoc CGI
or
man module
Example: man Mail::Send
-- READ SOURCE CODE
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
-- SHOW THE PATH WHERE A MODULE IS INSTALLED
perldoc -l module
Example: perldoc -l Catalyst
check if a module is installed
( categories: installing modules | perl modules )
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
No comments:
Post a Comment