hey_david has asked for the wisdom of the Perl Monks concerning the following question:
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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Which Library Am I Using?
by ChemBoy (Priest) on May 29, 2003 at 16:25 UTC | |
|
Re: Which Library Am I Using?
by zby (Vicar) on May 30, 2003 at 08:16 UTC | |
|
Re: Which Library Am I Using?
by Fletch (Bishop) on May 29, 2003 at 16:04 UTC |