Locate which path/file is loaded for a Perl module

09 Mar 2010

You want to figure out which is the source file being loaded for a given Perl module.

Throw the following code in a file named whichpm on a sensible location:

#!/usr/bin/perl -w
$M = shift @ARGV;
die "Usage:\n  whichpm Some::Module\n" unless defined $M;
eval("use $M; 1") or die "Can't locate module $M in \@INC\n";
$M =~ s|::|/|g;
print $INC{"$M.pm"}, "\n";

Make the file executable and then use, e.g., as:

$ whichpm Date::Manip

This recipe has also been packaged as a script on github: whichpm.