Unknown User wrote:
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

perldoc perlrun
[ SNIP ]
    PERL5LIB    A list of directories in which to look for Perl library
                files before looking in the standard library and the
                current directory.  Any architecture-specific
                directories under the specified locations are
                automatically included if they exist (this lookup being
                done at interpreter startup time.)

                If PERL5LIB is not defined, PERLLIB is used.
                Directories are separated (like in PATH) by a colon on
                unixish platforms and by a semicolon on Windows (the
                proper path separator being given by the command "perl
                -V:path_sep").

                When running taint checks (either because the program
                was running setuid or setgid, or the -T or -t switch
                was specified), neither variable is used. The program
                should instead say:

                    use lib "/my/directory";
[ SNIP ]
    PERLLIB     A list of directories in which to look for Perl library
                files before looking in the standard library and the
                current directory.  If PERL5LIB is defined, PERLLIB is
                not used.

                The PERLLIB environment variable is completely ignored
                when perl is run in taint mode.


Perhaps you are thinking of Perl's built-in @INC array?


<module1>  <module2>  <module3>  ...
        for my $toadd (split(/:/,$ENV{"INC"})) {
                push(@INC,"$toadd");
        }
}

No need to modify @INC:

use Env qw/ @PERL5LIB @PERLLIB /;

Then later on:

for my $path ( @INC, @PERL5LIB, @PERLLIB ) {


while (my $module = shift) {

So you are iterating over the module name in @ARGV? Why not just iterate over @ARGV:

for my $module ( @ARGV ) {

        print "=====>  Looking for module $module<=====\n";
        my $modpath = "";
        $module .= '.pm' if $module !~ /pm$/;

ITYM:

        $module .= '.pm' if $module !~ /\.pm\z/;


        if ($module =~ /^([\d\w:]+)::([\d\w]+.pm)$/) {

The \w character class already includes the \d character class. The period matches every character so you want to escape it to match a literal period character:

        if ($module =~ /^([\w:]+)::(\w+\.pm)$/) {


                $modpath = $1;
                $module = $2;
        }
        $modpath =~ s!::!/!g;
        &findmodule($modpath,$module);

You shouldn't use an ampersand when calling a subroutine:

        findmodule( $modpath, $module );


}

sub findmodule() {

Your prototype says to accept *NO* arguments yet you want to accept two arguments. You should not use prototypes.

sub findmodule {


        my $modpath = $_[0];
        my $module = $_[1];

That is usually written as:

        my ( $modpath, $module ) = @_;


        for my $path (@INC) {
                $path .= "/$modpath";
                if ( -d "$path" ) {

perldoc -q quoting


                        find( sub { print "$File::Find::name\n" if 
$File::Find::name =~
m!$modpath/$module$!} , $path);

You are using File::Find to find a single file on a single path. You probably just need to use the -e or -f operator.

Or perhaps you just need:

my $path = qx{ perldoc -l $module 2>/dev/null };


                }
        }
}

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.

Incorrect.



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to