20051224 12:51 by javier
Are you wondering where the heck does some arcane module come from? Wonder no more, perlwhich comes to the rescue:
#!/usr/bin/perl
use strict;
use File::
Spec;
my $module = shift @ARGV;
$module=~s,\.,,igs;
my $pm=$module.‘.pm’;
my @path = split(/::/,$pm);
my $found = 0;
foreach my $dir (@INC) {
my $file = File::Spec->catfile($dir,@path);
if(-f $file) {
print $file,“\n“;
$found=1;
}
}
exit(!$found);
(Download)
Next time you need to know some module’s path just run it like this:
$ perlwhich Data::Dumper
/usr/lib/perl/5.8/Data/Dumper.pm
If a module resides in multiple locations under @INC, perlwhich will let you know as well:
$ perlwhich Salesforce
/usr/local/lib/site_perl/Salesforce.pm
/usr/local/share/perl/5.8.4/Salesforce.pm
This entry was posted
on Saturday, December 24th, 2005 at 12:51 and is filed under Code, General, Perl.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
December 24th, 2005 at 23:00
“perldoc -l Module::Name” does this job almost as well, unless there’s no pod, or the pod comes from a separate file.
“perldoc -m Module::Name” dumps that file to stdout - great for grepping.