Perl – How to find which file Perl loaded when I use a module

moduleperl

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?

Best Answer

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",
}