A script to find modules in the paths listed in "@INC". The user can specify the full module name or just part of it or even use a regex if passed in quotes (i.e. findINC 'File.*')
I find this to be a useful script when trying to determine if I've got a particular module loaded up, but I can't help but feel I'm reinventing the wheel... Is there another way to do this?
#!/usr/bin/perl -w
######################################################################
+###########
#
# findINC
# Wed Sep 5 2001
# Rich Reuter
#
# Find a perl module in @INC. Can match part or all of a module name.
#
######################################################################
+###########
#######################################################
# Setup variables and packages
#######################################################
use strict;
use File::Find;
my @dirs = @INC;
# can use 'push(@dirs,"<dir_name>");' if there are dirs
# that are used to store modules, but is not part of @INC
my $module;
#######################################################
# MAIN
#######################################################
# Make sure that only one module name has been specified
if ((!$ARGV[0]) || ($ARGV[1])) {
die qq(Specify one module to search for!\n);
} else {
$module = $ARGV[0];
}
# Substitute "::" with "/" to build path name
$module =~ s|::|/|g;
find (\&checkForModule, @dirs);
sub checkForModule() {
my $element = $File::Find::name;
if ($element =~ $module) {
# Re-substitute "/" with "::" for printing purposes
$module =~ s|/|::|g;
print qq($module matched at $element\n);
}
}