A Private Stash (of modules) - Page 168
April 16, 2001
After installing modules with reckless abandon, we've probably
sufficiently populated ~lonelyone/perl/modules by now. The
last link in the chain is convincing Perl, which would not
normally otherwise, to look here to find these modules. Perl,
like most of us, is egocentric. If you don't grab its head and
make it look at you, it'll look at its own navel.
So, the very typical approach to a Perl script:
#!/usr/bin/perl
use DBI;
use Create::PDF;
Its going to choke, because Perl will look in its own navel to
find the modules DBI and Create::PDF. When Perl coughs up a lung
over a missing module, it looks quite like this (squeamish? turn
away):
Can't locate DBI.pm in @INC
(@INC contains: /usr/local/lib/perl5/5.6.1/i686-linux
/usr/local/lib/perl5/5.6.1
/usr/local/lib/perl5/site_perl/5.6.1/i686-linux
/usr/local/lib/perl5/site_perl/5.6.1
/usr/local/lib/perl5/site_perl/5.6.0/i686-linux
/usr/local/lib/perl5/site_perl/5.6.0
/usr/local/lib/perl5/site_perl .) at test.pl line 6.
BEGIN failed—compilation aborted at test.pl line 6.
[Lines 1 and 2 above are one line as are lines 3 and 4, 5 and
6, and 7 and 8. They have been split for formatting
purposes.]
It's a big, ugly error. Perl is saying, I've looked all over for
DBI.pm (module scripts end in .pm) and can't find it
anywhere (anywhere, by the way, happens to be the
following places). What we need to do is tell Perl where we've
stashed our modules.
Our example has assumed that our Perl scripts would reside in
~lonelyone/perl and the modules would be in
~lonelyone/perl/modules. In that case, one small addition to our
script will point Perl's head in the right direction.
#!/usr/bin/perl
use lib './modules';
use DBI;
use Create::PDF;
Of course, depending on the relationship between the location of
your Perl scripts, and your Perl modules, you would need to
adjust the "use lib" path accordingly. Additionally, you can add
several "use lib" lines if you have more than one location that
you want Perl to seek for modules.
A Good Yield
Thanks to the CPAN module, you can now browse about the
comprehensive set of Perl modules in one centralized hoe-down of
a farmer's market. Being limited to your own home directory on a
host's server needn't be limiting at all, now that you see how to
retrieve, install, and include additional Perl modules at your
heart's content.
Of course, CPAN is available on the Web,
too. Consult their Web-based search
to browse the module archive from a browser, which some prefer to
help track down a module of choice. You can then turn to the CPAN
shell to invoke the installation.
They Shoot Coders, Don't They? - Page 167
The Perl You Need to Know Part 23: CPAN, a Farmer's Market for Perl - Page 164
The Perl You Need to Know Part 24: Introduction to Object Oriented Perl - Page 169
|