Ok, here's the code - it's not the cleanest code, but it seems to work for the relatively few modules I've tried it with. I call it 'pwhich' which functions sort of like the 'which' command on Linux:
#!/usr/bin/perl -w use strict; my $perl_module; BEGIN { my $ct_args = @ARGV; if ($ct_args != 1) { print "\nUsage: pwhich <perl module name>\n\n"; print "Example: pwhich DBI\n\n"; exit; } $perl_module = shift; }; eval "use $perl_module"; die "Can't find Perl module $perl_module!\n" if $@; my $inc_key = "$perl_module.pm"; $inc_key =~ s!::!/!g; print "inc_key = $inc_key\n"; my $abs_filename = $INC{$inc_key}; print "\n"; print "Module: $perl_module\n"; print "Location: $abs_filename\n"; open(IN,"<$abs_filename") || die "Can't open $abs_filename!"; my $version = ""; while (<IN>) { if (/\s*\$[\w:]*VERSION\s*=[ "']*([0-9_\.]+)/i) { $version = $1; last; } } close(IN); print "Version: $version\n\n";

In reply to Re: module location by hmerrill
in thread module location by hmerrill

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.