Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perldoc -l <module name> 2

Status
Not open for further replies.

hmerrill

Programmer
Dec 4, 2000
473
US
I saw this tip this morning from another list - there is a

perldoc -l <module name>

(that's a minus small L option) command that will tell you where in the @INC perl path the module exists. For example, on my system if I do

perldoc -l DBI

it spits this back:

/usr/lib/perl5/site_perl/5.005/i386-linux/DBI.pm

So I enhance that a little with this script that I called &quot;pwhich&quot;:
---------------------------------------

#!/usr/bin/perl -w

#############################################################################
# Name: pwhich
# Purpose: Perl version of &quot;which&quot; command
# Takes In: 1. Perl module name (Ex: DBI, DBD::Oracle)
#
# Writes Out: Either a. &quot;No documentation found for &quot;XYZ&quot;
#
# where &quot;XYZ&quot; is the name of a Perl module specified
# by the user that does *NOT* exist,
#
# Or b. line 1 - the @INC location of the perl module, and
# line 2 - the $Id version of the perl module
#############################################################################

use strict;

my $ct_args = @ARGV;

if ($ct_args != 1) {
print &quot;\nUsage: pwhich <perl module name>\n\n&quot;;
print &quot;Example: pwhich DBI\n\n&quot;;
exit;
}

my $perl_module = shift;

my $abs_filename = `perldoc -l $perl_module 2>&1`;

print &quot;\n&quot;;

print &quot;$abs_filename&quot;;
if ($abs_filename =~ /^No documentation found/) {
print &quot;\n&quot;;
exit;
}
chomp($abs_filename);

open(IN,&quot;<$abs_filename&quot;) || die &quot;Can't open $abs_filename!&quot;;
while (<IN>) {
if (/\s*\$[\w:]*VERSION\s*=/) {
print;
last;
}
}
close(IN);

print &quot;\n&quot;;
---------------------------------------

If I now run this

pwhich DBI

it spits this back:

/usr/lib/perl5/site_perl/5.005/i386-linux/DBI.pm
$DBI::VERSION = &quot;1.15&quot;; # ==> ALSO update the version in the pod text below!

Thought some people here might find this useful.
Hardy Merrill
Mission Critical Linux, Inc.
 
Good job! That might come in handy!
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
I find this helpful because prior to this, if I wanted to find out the version of a module, I'd get into CPAN, and at the CPAN> prompt, I'd issue I think it is

CPAN> m DBI

if I wanted to see the module info(including version) for DBI.

But this new &quot;pwhich&quot; gives me a local quick way of getting the same info without having to invoke CPAN.

Anyone know of other way(s) to find out the version of a particular module?
Hardy Merrill
Mission Critical Linux, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top