We have multiple installations of some perl modules on our server, and sometimes we want to know which one of 'em a script is calling. (E.g. Maybe we want to know how its user-serviceable parts have been configured.)

So, I wrote a script to figure it out (below), because, well, it seemed like fun at the time. But what I want to know is, is there a one-liner (or there-abouts) to do this?

Thanks!

#!/usr/bin/perl -w # Give it a Perl library name. # It tells you the location of that library that # /usr/bin/perl would use. # Useful when you've got multiples of the same library # floating around. # # Accomplished by intersecting your @INC array with the # locate <library> command (so its accuracy depends # on an up-to-date locate database (see updatedb)). use strict; @ARGV == 1 or die "Usage: whichlib.pl <library name>\n" . " E.g.: whichlib.pl CGI/Carp.pm\n" . " or: whichlib.pl CGI::Carp\n"; chomp(my $lib = $ARGV[0]); if ($lib =~ m/::/) { $lib =~ s/::/\//g; $lib = $lib . '.pm'; } chomp(my @lib_locations = `locate $lib`); foreach my $inc_path (@INC) { #ex: /usr/share/perl/5.6.1 foreach my $lib_loc (@lib_locations) { #ex: /usr/share/perl/5.6.1/ +CGI/Carp.pm # strip off the slash + lib name (e.g. strip '/CGI/Carp.pm') my $lib_loc_path = $lib_loc; $lib_loc_path =~ s/\/$lib//; if ($inc_path eq $lib_loc_path) { # found it! print "$lib_loc\n"; exit(0); } } } print "No-match-found.\n"; exit(1);

In reply to Which Library Am I Using? by hey_david

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.