in reply to Module Finder

But then you have to do the Module to Module-partial-path yourself, mentally. Not that hard, indeed. And one may actually prefer it that way. I wouldn't. However what's more important is that you're transversing all @INC recursively whereas you already know the potential locations for the wanted package. Also suppose you want to find the location of That::Particular::Foo. With your method unless I'm missing something, you're bound to search for 'Foo', and with your match you'll also get not only That::Other::Foo, but also That::Particular::eFoOZ. Last, there are indeed case insensitive (but case preserving) fs'es in widespread use, however case does matter for [Pp]erl, so I would most definitely avoid /i.

I would proceed like thus instead:

#!/usr/bin/perl use strict; use warnings; use File::Spec::Functions; die "Usage: $0 <module> [<modules>]\n" unless @ARGV; ($\,$,)=("\n")x2; for my $mod (@ARGV) { print "Searching for `$mod':"; $mod =~ s{::}{/}g; $mod .= '.pm'; my @results=grep -f, map {catfile $_, $mod} @INC; warn "`$mod' not found\n" and next unless @results; print @results, ''; } __END__

Of course if you don't mind your particular module being actually loaded, and you generally shouldn't care, then you may ask perl to tell you where it found it, inspecting %INC:

C:\temp>perl -MFile::Find -le "print $INC{'File/Find.pm'}" C:/Programmi/Perl/lib/File/Find.pm

Replies are listed 'Best First'.
Re^2: Module Finder
by Dietz (Curate) on Oct 19, 2006 at 06:21 UTC

    If you have perldoc available on your system (some sysadmins refuse to install it), it's as easy as:

    on AIX:

    $ perldoc -l File::Find /usr/opt/perl5/lib/5.8.2/File/Find.pm
    or on Windows (returning backslashes):
    C:\>perldoc -l File::Find C:\Perl\lib\File\Find.pm

      That's definately a good way to find a module, but if I don't know the root or branches, it does me no good...

        The example with perldoc wasn't meant to be a reply to your OP. It was a reply to blazar's File::Find one liner.

        However, if you happen to know the full last part of the module name you're searching for (i.e. Digest::MD5) you could use a recursive search (-r) to find the path to the pm file:

        $ perldoc -l -r MD5 /usr/lib/perl/5.8/Digest/MD5.pm

        Update:
        I just noticed that perldoc doesn't show multiple matches:

        $ perldoc -li html::parser /usr/lib/perl5/HTML/Parser.pm $ perldoc -li xml::parser /usr/lib/perl5/XML/Parser.pm $ perldoc -lri parser /usr/lib/perl5/HTML/Parser.pm
Re^2: Module Finder
by innominate (Beadle) on Oct 31, 2006 at 15:22 UTC
    Yep, the case insensitivity was completely intended. Mainly for those odd instances like Xbase and XBase. I guess, to make it a bit more robust, I should have tossed an argument parser to allow that option to be turned on/off.


    Truthfully, this came about when I was working on a system that had no net connection, but I couldn't remember the root of the MD5 module. (Moronic, I know, but I hadn't used it in a loooong time.)

    With this, it returns what I wanted (Digest::MD5), along with any other MD5 related modules. Given, they may not be very closely related, but I could toss the info into perldoc and find out.


    Thanks for the tips though!

    -inno