#!/usr/bin/perl -w # Give it a Perl library name. # It tells you the location of that library that # /usr/bin/perl would use. # Useful when you've got multiples of the same library # floating around. # # Accomplished by intersecting your @INC array with the # locate command (so its accuracy depends # on an up-to-date locate database (see updatedb)). use strict; @ARGV == 1 or die "Usage: whichlib.pl \n" . " E.g.: whichlib.pl CGI/Carp.pm\n" . " or: whichlib.pl CGI::Carp\n"; chomp(my $lib = $ARGV[0]); if ($lib =~ m/::/) { $lib =~ s/::/\//g; $lib = $lib . '.pm'; } chomp(my @lib_locations = `locate $lib`); foreach my $inc_path (@INC) { #ex: /usr/share/perl/5.6.1 foreach my $lib_loc (@lib_locations) { #ex: /usr/share/perl/5.6.1/CGI/Carp.pm # strip off the slash + lib name (e.g. strip '/CGI/Carp.pm') my $lib_loc_path = $lib_loc; $lib_loc_path =~ s/\/$lib//; if ($inc_path eq $lib_loc_path) { # found it! print "$lib_loc\n"; exit(0); } } } print "No-match-found.\n"; exit(1);