Tuesday 25 January 2011

Perl Tip: finding module path

I thought I'd share a little Perl Tip/Trick that saves me a lot of trouble. Say you have a perl module installed and you need to make a correction to the source code. For some reason you can't find where the module installed to though. You could spend time using 'find' searching through folders or do this:

perl -M'Data::Dumper' -M'' -e 'print Dumper(\%INC)' 

This will dump all the modules loaded out to screen for you. You can of course pipe this into grep to look for the specific module or modules you want. You will then get the path.

Observe:



c0malod@Takeshi:/Tools$ perl -M'Data::Dumper' -M'Time::HiRes' -e 'print Dumper(\%INC)'
$VAR1 = {
          'warnings/register.pm' => '/usr/share/perl/5.10/warnings/register.pm',
          'bytes.pm' => '/usr/share/perl/5.10/bytes.pm',
          'XSLoader.pm' => '/usr/lib/perl/5.10/XSLoader.pm',
          'Carp.pm' => '/usr/share/perl/5.10/Carp.pm',
          'Exporter/Heavy.pm' => '/usr/share/perl/5.10/Exporter/Heavy.pm',
          'vars.pm' => '/usr/share/perl/5.10/vars.pm',
          'strict.pm' => '/usr/share/perl/5.10/strict.pm',
          'Time/HiRes.pm' => '/usr/lib/perl/5.10/Time/HiRes.pm',
          'Exporter.pm' => '/usr/share/perl/5.10/Exporter.pm',
          'warnings.pm' => '/usr/share/perl/5.10/warnings.pm',
          'AutoLoader.pm' => '/usr/share/perl/5.10/AutoLoader.pm',
          'overload.pm' => '/usr/share/perl/5.10/overload.pm',
          'Config.pm' => '/usr/lib/perl/5.10/Config.pm',
          'DynaLoader.pm' => '/usr/lib/perl/5.10/DynaLoader.pm',
          'Data/Dumper.pm' => '/usr/local/lib/perl/5.10.1/Data/Dumper.pm'
        };


OR:
c0malod@Takeshi:/Tools$ perl -M'Data::Dumper' -M'Time::HiRes' -e 'print Dumper(\%INC)' | grep 'HiRes'
          'Time/HiRes.pm' => '/usr/lib/perl/5.10/Time/HiRes.pm',

Simple little trick, but it works wonders. Cheers.


No comments:

Post a Comment