Perl – How to 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?

Best Answer

Yes, %INC contains the full path a module was loaded from.


$ perl -M'Data::Dump qw(pp)' -e 'pp(\%INC)'
  "Data/"         => "/usr/share/perl5/Data/",
  ""          => "/usr/share/perl/5.10/",
  "List/"         => "/usr/lib/perl/5.10/List/",
  "Scalar/"       => "/usr/lib/perl/5.10/Scalar/",
  ""          => "/usr/lib/perl/5.10/",
  ""          => "/usr/share/perl/5.10/",
  ""            => "/usr/share/perl/5.10/",
  ""              => "/usr/share/perl/5.10/",
  ""          => "/usr/share/perl/5.10/",
  "warnings/" => "/usr/share/perl/5.10/warnings/",