
Let's say you have a Perl script named example.pl that wants to use the foo.pm (which is a homegrown Perl module) and Net::SSH::Perl module.
#!/usr/bin/perl
use strict;
use warnings;
use foo;
use Net::SSH::Perl;
Let's say you invoke example. pl . .
perl example.pl
. . . and the following is returned.
Can't locate foo.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at example.pl line 4.
Can't locate Net::SSH::Perl in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at example.pl line 5.
When a module is installed in Perl, such as Net::SSH::Perl or Net::LDAP, the module adds information to a file called perllocal.pod on your system. The perllocal.pod is usually located at /usr/local/lib/perl5/version/arch. The vast majority of modules append information to the perllocal.pod file. The perldoc -l module_name command will determine if the perllocal.pod file contains an entry for a certain module. In this example, the Net::SSH::Perl module is installed on the system. Be careful, as this search is CaSe SenSiTiVe.
~]# perldoc -l Net::SSH::Perl
/usr/local/lib64/perl5/Net/SSH/Perl.pm
For homegrown Perl module, such as foo.pm in this example, you will have a file somewhere on your system that contains the file, for example, perhaps at /usr/share/perl/modules/foo.pm.
/usr/share/perl/modules/foo.pm
One option here is to include use lib followed by the directory that contains the module in your Perl script.
#!/usr/bin/perl
use strict;
use warnings;
use lib "/usr/share/perl/modules";
use lib "/usr/local/lib64/perl5";
use foo;
use Net::SSH::Perl;
Did you find this article helpful?
If so, consider buying me a coffee over at