© copyright 01.Jan.2002 by Paul Bradley filed under Perl
When you have been developing Perl CGI scripts for while you will invariable need to install one of the many useful modules located in the Comprehensive Perl Archive Network. CPAN is a group of servers around the world which provide access to Perl source code, and hundreds of modules that have been contributed by volunteers.
Part of what makes CPAN powerful, is that Perl supports it directly with the CPAN.pm module which is distributed with Perl. Many of the database projects I have developed could not of been possible without the templating system HTML::Template.
On most operating systems, you can install a CPAN module by typing the following from the command line :-
perl -MCPAN -e install HTML::Template
where HTML::Template is the name of the module you wish to install. This command will automatically find, download, compile, and install the module onto your system.
If this is the first time you have run the command on your system, you may be prompted with a series of multi-choice questions, so that the CPAN module can find the nearest FTP server.
If you are using ActiveState Perl on a windows based server, then you can use the PPM command-line utility.
from the /bin sub folder of perl type:- ppm<return>
then type:- install HTML::Template<return>
If you are using a web hosting account which doesn't give you access to the operating system, so that you can install perl modules as described above, then you can still use modules by setting up your own lib folder.
Typically the best place to locate the lib folder is under you cgi-bin directory. The tree structure below shows where you would need to upload the Template.pm file to use Html::Template.
/
|
--/cgi-bin
|
--/lib
|
--/Html
Template.pm
The module name will determine where the .pm files need to be located under your lib directory. The text prior to the :: will become the directory name. For example the Calc.pm module that comes with Date::Calc will need to go into a sub-directory of lib called Date.
/
|
--/cgi-bin
|
--/lib
|
--/Html
| Template.pm
|
--/Date
Calc.pm
To use the module within a Perl script, you need to call the Lib module, passing it the full system path to your lib folder. You can then use the modules in the normal way, see the example code below. Please note some CPAN modules rely on other modules being present, and if that's the case then you will need to upload them as well.
#/path/to/perl -w
use strict;
use lib(/full/path/to/cgi-bin/lib);
use Html::Template;
.. rest of code
About the Author
Paul Bradley is a VB.NET software developer living and working in Cumbria. He provides PHP & MySQL bespoke development services via his software development company, Carlisle Software Limited.
He has over 20 years programming experience.