Re: oneliner to get module version
by graff (Chancellor) on Jun 14, 2009 at 23:54 UTC
|
Right -- I have something quite similar (but a little shorter ;) in my .bashrc:
pmversion ()
{
perl -M$1 -le "print $1->VERSION"
}
Note that bash interpolates both instances of "$1" before perl gets to read the script.
Also, since I tend to work in a rather "diversified" network environment, it's useful to be able to spot the path to a given module:
pmpath ()
{
perl -M$1 -le "print \$INC{'$1.pm'}"
}
Here, I have to guard (escape) the "$" in front of INC so the shell leaves it as-is and perl sees it as "$INC"; bash ignores the single-quotes because they're inside "...", and perl does the right thing there, because $1 has already been interpolated by the shell.
UPDATE: The "pmpath" approach above only works for "top-level" modules. In order to get the path for a module like "Foo::Bar::Baz", it's a bit more complicated:
pmpath ()
{
perl -M$1 -le "(\$_='$1')=~s{::}{/}g; print \$INC{\$_.'.pm'}"
}
My apologies for the misleading initial version.
FINAL UPDATE: There's actually a much better method for finding the path to a module, as pointed out by Your Mother below. | [reply] [Watch: Dir/Any] [d/l] [select] |
|
cow@moo[609]~/bin>perldoc -l CGI
/usr/local/lib/perl5/5.10.0/CGI.pm
| [reply] [Watch: Dir/Any] [d/l] |
|
alias pmpath='perldoc -l'
Much better -- thank you! | [reply] [Watch: Dir/Any] [d/l] [select] |
|
That is shorter, and I like pmpath().
I have always thought I needed to use local for a Bash function since the args might change from line to line, but you're right, that's really for a multiline shell function (or am I just being paranoid?)
SSF
| [reply] [Watch: Dir/Any] |
Re: oneliner to get module version
by syphilis (Archbishop) on Jun 15, 2009 at 03:31 UTC
|
Nice idea - and I've just stuck it in my bashrc on my linux box, where it's working fine.
However, in the form in which you've posted it, it won't work with Parse::RecDescent, Inline::C and (probably) some of the other Inline::* modules. So instead, I've written the perl command as:
perl -le "require $m;print $m->VERSION"
and that seems to work fine for *all* modules (the ones I tested, at least).
Cheers, Rob
| [reply] [Watch: Dir/Any] [d/l] |
Re: oneliner to get module version
by Anonymous Monk on Jun 15, 2009 at 07:28 UTC
|
CGI: 3.43
strict: 1.03
| [reply] [Watch: Dir/Any] [d/l] |
Re: oneliner to get module version
by planetscape (Chancellor) on Jul 06, 2009 at 07:50 UTC
|
| [reply] [Watch: Dir/Any] |
|
The batch file (equivalent to bart's) that I'm using as a result of this thread is:
@echo off
perl -le "require %1; print %1->VERSION"
As mentioned above, loading the module with '-M' or 'use' won't work with some modules - eg Inline::C, Inline::CPP, Parse::RecDescent. With bart's version.bat I get:
C:\_32>version Parse::RecDescent
Usage: perl -MLocalTest - <grammarfile> <classname>
C:\_32>version Inline::C
It is invalid to use 'Inline::C' directly. Please consult the Inline
documentation for more information.
at -e line 0
BEGIN failed--compilation aborted.
C:\_32>version Inline::CPP
It is invalid to use 'Inline::CPP' directly. Please consult the Inline
documentation for more information.
at -e line 0
BEGIN failed--compilation aborted.
Cheers, Rob | [reply] [Watch: Dir/Any] [d/l] [select] |
Re: oneliner to get module version
by Tux (Canon) on Jul 07, 2009 at 07:56 UTC
|
$ perl -MV=V
V
/pro/lib/perl5/site_perl/5.8.8/V.pm: 0.13
$ perl -MV=DBI
DBI
/pro/lib/perl5/site_perl/5.8.8/x86_64-linux/DBI.pm: 1.609
$ perl -MV=charnames
charnames
/pro/lib/perl5/5.8.8/charnames.pm: 1.05
$
Enjoy, Have FUN! H.Merijn
| [reply] [Watch: Dir/Any] [d/l] |
|
perl -MDevel::Modlist -MCGI -MSafe -Mautodie -e 1
ActivePerl::Config
ActiveState::Path 1.00
AutoLoader 5.67
CGI 3.43
CGI::Util 1.5_01
Carp 1.10
Carp::Heavy
Config
Config_heavy.pl
Cwd 3.3
C:::Perl::site::lib::sitecustomize.pl
Exporter 5.63
Exporter::Heavy 5.63
Fatal 2.05
Fcntl 1.06
File::Basename 2.77
List::Util 1.21
Opcode 1.0601
POSIX 1.1501
Safe 2.16
Scalar::Util 1.21
Tie::Hash 1.03
Tie::RefHash 1.38
XSLoader 0.10
autodie 2.05
constant 1.17
overload 1.06
re 0.0601
subs 1.00
vars 1.01
warnings 1.05_01
warnings::register 1.01
| [reply] [Watch: Dir/Any] [d/l] |
Re: oneliner to get module version
by Khen1950fx (Canon) on Jun 26, 2009 at 07:25 UTC
|
| [reply] [Watch: Dir/Any] [d/l] |