How do you find the version of an installed Perl module?
This is in an answer down at the bottom, but I figure it important enough to live up here. With these suggestions, I create a function in my .bashrc
function perlmodver {
perl -M$1 -e 'print "Version " . $ARGV[0]->VERSION . " of " . $ARGV[0] . \
" is installed.\n"' $1
}
I wrote a small script to report that: perlver.
It assumes that the module defines a $VERSION. If the module doesn't define a $VERSION, it will still tell you where the
.pm
file is, so you can examine it manually. You can also check several modules at once:If you are lucky, the module will have a package variable named $VERSION:
This is needed for modules to be distributed on CPAN, but internally developed modules might follow a different convention or none at all.
Why are you trying to get the version of the module? Do you need this from within a program, do you just need the number to pass to another operation, or are you just trying to find out what you have?
I have this built into the
cpan
(which comes with perl) with the-D
switch so you can see the version that you have installed and the current version on CPAN:If you want to see all of the out-of-date modules, use the
-O
(capital O) switch:If you want to see this for all modules you have installed, try the
-a
switch to create an autobundle.In addition, for modules that use Exporter.pm, you can get this information with this trick:
For modules that don't use Exporter.pm, a slightly longer trick reports the same information:
Most modules (especially ones from The CPAN) have a $VERSION variable:
There is a less-typing trick, that works provided your module doesn't have something insane like a Unix timestamp as a version number.
This works because what it translates to is
i.e. a version of Foo::Bar that's at least version 9999 or newer. And what you get is
(Neat trick I learned from Matt Trout.)