in reply to Re: module location
in thread module location

DBI was just an example of a module name. The script I'm working on will take in the name of any perl module and will tell you
1. if the module is installed on the system 2. if it is installed, what version ($VERSION) it is, and 3. if it is installed, exactly where on the system it resides (absolute file name)
It's not rocket science - I'm sure others (like Broquaint above with Module::Locate) have probably already done this, but I'll post the code when I'm done.

Replies are listed 'Best First'.
Re: Re: Re: module location
by jZed (Prior) on Nov 07, 2003 at 16:45 UTC
    Well, for DBI, this tells you all three of those things:

    perl -MDBI=9999

    But good luck on a more general solution, seems like there have been some good suggestions for you.
      Part of that doesn't work, at least on my system. Here's what I get:
      [hmerrill@merrill bin]$ perl -MDBI=9999 DBI version 9999 required--this is only version 1.32 at /usr/lib/perl5/5.8.0/Exporter/Heavy.pm line 121. BEGIN failed--compilation aborted.
      It does print the version of DBI(1.32), but notice that the path name refers to Exporter::Heavy, and not DBI.

        It's a bit long as one-liners go, but it does the job and could probably be golfed.

        P:\test>perl -le"BEGIN{eval qq[use $ARGV[0]]} print ${$ARGV[0].'::VERS +ION'}; $ARGV[0]=~s[::][/]g; print $INC{$ARGV[0].'.pm'}" File::Find 1.04 d:/Perl/lib/File/Find.pm

        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        Hooray!
        Wanted!

Re: Re: Re: module location
by broquaint (Abbot) on Nov 07, 2003 at 16:57 UTC
    use Module::Locate 'locate'; die "Usage: $0 MODULE\n" unless @ARGV; my $mod = shift @ARGV; my $path; if(eval{ require( $path = locate $mod ) }) { die "$mod missing version number\n" unless $mod->VERSION; print "$mod version ", $mod->VERSION, " installed at $path\n"; } else { die "$mod not installed\n"; }
    HTH

    _________
    broquaint