How do I find which file Perl loaded when I use a module?
in Perl, when I do use <module name> <ver>;
, the system finds the .pm
file for the library somewhere in the @INC
path.
Is there a reliable way to which file was actually loaded?
Solution 1:
Yes, %INC
contains the full path a module was loaded from.
Example:
$ perl -M'Data::Dump qw(pp)' -e 'pp(\%INC)'
{
"Data/Dump.pm" => "/usr/share/perl5/Data/Dump.pm",
"Exporter.pm" => "/usr/share/perl/5.10/Exporter.pm",
"List/Util.pm" => "/usr/lib/perl/5.10/List/Util.pm",
"Scalar/Util.pm" => "/usr/lib/perl/5.10/Scalar/Util.pm",
"XSLoader.pm" => "/usr/lib/perl/5.10/XSLoader.pm",
"overload.pm" => "/usr/share/perl/5.10/overload.pm",
"strict.pm" => "/usr/share/perl/5.10/strict.pm",
"vars.pm" => "/usr/share/perl/5.10/vars.pm",
"warnings.pm" => "/usr/share/perl/5.10/warnings.pm",
"warnings/register.pm" => "/usr/share/perl/5.10/warnings/register.pm",
}
Solution 2:
If the module has pod documentation, and if you can guarantee that the perldoc utility in your PATH belongs to the same perl that is running your script, then this command will often give you the actual file being found:
perldoc -l ModuleName
Solution 3:
perl -M'LWP' -e 'use Data::Dumper; print Dumper \%INC' | grep LWP
This will list out the LWP module location on the disk and also lists out modules loaded inside LWP.
'LWP.pm' => '/usr/lib/perl5/5.10.0/LWP.pm',
'LWP/Protocol.pm' => '/usr/lib/perl5/5.10.0/LWP/Protocol.pm',
'LWP/UserAgent.pm' => '/usr/lib/perl5/5.10.0/LWP/UserAgent.pm',
Solution 4:
You want to look in the %INC
variable, which records the filename it loaded for the libraries you load with do
, require
, or use
. See perlvar for the details.