I started working on a new Unix system yesterday — an HP-UX system I’ve never worked on before — and quickly realized that I needed some Perl modules installed. While working with another person the question quickly came up, “How do you know where Perl is looking for currently installed modules?”
That turns out to be a very interesting question.
In the Java world, this is the same as asking “What is the Java CLASSPATH?”, which you can easily see by looking at your system environment variables. Perl uses an @INC
variable that contains the directories it will search in when you specify that you want to include a module, but you can’t look at it like an environment variable.
The solution
Although Perl doesn’t have something like the CLASSPATH environment variable you can easily look at, you can print the @INC
variable with a simple one-line command. The following Perl command shows the directories that Perl looks in when it tries to load modules:
perl -e 'print "@INC";'
Perl INC path on Mac OS X
Although I’m not working on that HP-UX system right now, when I run this command on my Mac OS X computer I get this output:
/sw/lib/perl5 /sw/lib/perl5/darwin /System/Library/Perl/5.8.8/darwin-thread-multi-2level /System/Library/Perl/5.8.8 /Library/Perl/5.8.8/darwin-thread-multi-2level /Library/Perl/5.8.8 /Library/Perl /Network/Library/Perl/5.8.8/darwin-thread-multi-2level /Network/Library/Perl/5.8.8 /Network/Library/Perl /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 .
Follow-up
In that previous code listing I changed the output format a little, but after a little digging around I found a way to make the printout look exactly as I’ve shown it above:
perl -e 'print join("\n", @INC);'
I don’t use Perl as much as I used to, so I find this command a little harder to remember, but the output is nicer.