Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to tell which @INC path a module was loaded from?

Tags:

perl

Use case

My sysadmin just installed a Perl module via rpm and despite the fact that I can successfully use it in a one-liner, I want to know where the module was installed.

I can obviously comb through each of the path locations in @INC, but is there a way for Perl to tell me where it successfully loaded the module from?

like image 798
Zaid Avatar asked Mar 21 '17 12:03

Zaid


1 Answers

That's what the %INC hash is for. It shows you where a module was loaded from.

$ perl -MDBI -MData::Dumper -E'say Dumper \%INC'
$VAR1 = {
          'XSLoader.pm' => '/usr/share/perl5/XSLoader.pm',
          'warnings/register.pm' => '/usr/share/perl5/warnings/register.pm',
          'List/Util.pm' => '/usr/local/lib64/perl5/List/Util.pm',
          'warnings.pm' => '/usr/share/perl5/warnings.pm',
          'DBI.pm' => '/usr/lib64/perl5/vendor_perl/DBI.pm',
          'overloading.pm' => '/usr/share/perl5/overloading.pm',
          'Config.pm' => '/usr/lib64/perl5/Config.pm',
          'Carp.pm' => '/usr/share/perl5/vendor_perl/Carp.pm',
          'bytes.pm' => '/usr/share/perl5/bytes.pm',
          'Exporter/Heavy.pm' => '/usr/share/perl5/vendor_perl/Exporter/Heavy.pm',
          'Scalar/Util.pm' => '/usr/local/lib64/perl5/Scalar/Util.pm',
          'strict.pm' => '/usr/share/perl5/strict.pm',
          'Exporter.pm' => '/usr/share/perl5/vendor_perl/Exporter.pm',
          'vars.pm' => '/usr/share/perl5/vars.pm',
          'constant.pm' => '/usr/share/perl5/vendor_perl/constant.pm',
          'overload.pm' => '/usr/share/perl5/overload.pm',
          'DynaLoader.pm' => '/usr/lib64/perl5/DynaLoader.pm',
          'Data/Dumper.pm' => '/usr/lib64/perl5/vendor_perl/Data/Dumper.pm',
          'feature.pm' => '/usr/share/perl5/feature.pm'
        };

Update: Actually, there's an easier method.

$ perldoc -lm Your::Module
like image 147
Dave Cross Avatar answered Oct 20 '22 01:10

Dave Cross