I have this script to find out where a perl module is on my machine:
[unkn...@knowme:~/bin]$ cat findmodule
#!/usr/bin/perl -w
use File::Find;
use strict;
if ($ENV{"INC"} ) { # INC=PATH1:PATH2 ./getmodule
<module1> <module2> <module3> ...
for my $toadd (split(/:/,$ENV{"INC"})) {
push(@INC,"$toadd");
}
}
while (my $module = shift) {
print "=====> Looking for module $module <=====\n";
my $modpath = "";
$module .= '.pm' if $module !~ /pm$/;
if ($module =~ /^([\d\w:]+)::([\d\w]+.pm)$/) {
$modpath = $1;
$module = $2;
}
$modpath =~ s!::!/!g;
&findmodule($modpath,$module);
}
sub findmodule() {
my $modpath = $_[0];
my $module = $_[1];
for my $path (@INC) {
$path .= "/$modpath";
if ( -d "$path" ) {
find( sub { print "$File::Find::name\n" if
$File::Find::name =~
m!$modpath/$module$!} , $path);
}
}
}
The problem is, for successive iterations of the module name in the
while loop, it does not appear to check in the correct paths, i assume
this is because File::Find needs to be reset every time.
[unkn...@knowme:~/bin]$ getmodule IO::Socket IO::Socket Socket
=====> Looking for module IO::Socket <=====
/usr/lib/perl5/5.8.8/i386-linux-thread-multi/IO/Socket.pm
=====> Looking for module IO::Socket <=====
=====> Looking for module Socket <=====
[unkn...@knowme:~/bin]$
Please let me know how i can fix it.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/