Checking to see if a Perl module is in your @INC path

As I started working on a new Unix system yesterday I needed to know if that system had certain Perl modules installed on it that I needed. In my case the specific Perl modules I needed were SOAP::Lite and the Error module.

One way to find out was to just install my Perl program and then try to run it, but because I knew I needed these modules beforehand I just ran the following commands to see if these modules were installed on this HP-UX system:

perl -e 'use SOAP::Lite;'


perl -e 'use Error;'

If I run these commands on a system that has SOAP::Lite and Error installed, Perl will simply return from these commands without printing any output. This lack of output indicates that Perl was able to successfully find (and use) this module -- there's no reason to show an error message because these commands will normally run inside of a larger script, and when there's no errors there's also no need for error output.

However, if I try the same command with a module that doesn't exist, like this:

perl -e 'use Foo::Bar::Baz;'

I'll get some output that looks like this:

Can't locate Foo/Bar/ in @INC (@INC contains: 
/Library/Perl/5.8.8 /Library/Perl /Network/Library/Perl/5.8.8/darwin-thread-multi-2level 
/System/Library/Perl/Extras/5.8.8/darwin-thread-multi-2level /System/Library/Perl/Extras/5.8.8 
/Library/Perl/5.8.6/darwin-thread-multi-2level /Library/Perl/5.8.6 /Library/Perl/5.8.1 
at -e line 1.
BEGIN failed--compilation aborted at -e line 1.

The general case

So, in the most general case, if you're trying to determine whether a Perl module named Foo is available for you to use, just use this command to check:

perl -e 'use Foo;'

How to modify your @INC include path

The final thing to remember is that if this message comes back with an error, it doesn't exactly mean that this module isn't installed on the current system, it just means that the module isn't in your @INC include path. If that happens to be these case, this article shows how you can modify your @INC include path.