How can I find the version of the installed Perl module?

How do you find the version of the installed Perl module?

This is the answer below, but I find it important enough to live 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 } 
+47
module perl cpan version
Sep 25 '08 at 20:16
source share
12 answers

Why are you trying to get the module version? Do you need this from within the program, you just need the number to go to another operation, or are you just trying to find out what you have?

I have a built-in cpan (which comes with perl) with the -D switch so that you can see the version you installed and the current version in CPAN:

 $ cpan -D Text :: CSV_XS

 Text :: CSV_XS
 -------------------------------------------------- -----------------------
         Fast 8bit clean version of Text :: CSV
         H / HM / HMBRAND / Text-CSV_XS-0.54.tgz
         /usr/local/lib/perl5/site_perl/5.8.8/darwin-2level/Text/CSV_XS.pm
         Installed: 0.32
         CPAN: 0.54 Not up to date
         H.Merijn Brand (HMBRAND)
         hmbrand@xs4all.nl

If you want to see all obsolete modules, use the -O (capital O) switch:

 $ cpan -O
 Module Name Local CPAN
 -------------------------------------------------- -----------------------
 Apache :: DB 0.1300 0.1400
 Apache :: SOAP 0.0000 0.7100
 Apache :: Session 1.8300 1.8700
 Apache :: SizeLimit 0.0300 0.9100
 Apache :: XMLRPC :: Lite 0.0000 0.7100
 ... and so on

If you want to see this for all the modules you have installed, try using the -a switch to create autorun.

+50
Sep 25 '08 at 21:19
source share

Most modules (especially from the CPAN list) have the $ VERSION variable:

 perl -MSome::Module -le 'print $Some::Module::VERSION' 
+48
Sep 25 '08 at 20:17
source share

VERSION is the UNIVERSAL method of all Perl classes. You can use it to get the version of the module (if it was installed, as usual).

Here is one liner where you only need to add the module name once:

 perl -le 'eval "require $ARGV[0]" and print $ARGV[0]->VERSION' Some::Module 
+27
Sep 25 '08 at 21:21
source share

There is a less typical trick that works if your module has nothing crazy, like a Unix timestamp, like a version number.

 perl -MFoo::Bar\ 9999 

This works because what he translates is

 use Foo::Bar 9999; 

i.e. Foo :: Bar version, at least version 9999 or later. And you get

 Foo::Bar version 9999 required--this is only version 1.1. BEGIN failed--compilation aborted. 

(The taming trick I learned from Matt Trout.)

+15
Sep 25 '08 at 20:48
source share

If you're lucky, the module will have a package variable called $ VERSION :

 $ perl -MCPAN -e 'print "$CPAN::VERSION\n"' 1.9205 

This is necessary for modules that need to be distributed across the CPAN, but internal modules may follow a different agreement or not at all.

+8
Sep 25 '08 at 20:19
source share

Thanks for answers! I created a function in my .bashrc to easily find the version of the Perl module:

 function perlmodver { perl -M$1 -e 'print $ARGV[0]->VERSION . "\n"' $1 } 
+4
Sep 25 '08 at 21:41
source share

Check out pmtools scripts on CPAN. If you are using a Debian (based) distribution, there is also a convenient pmtools package . This includes a script "pmvers" that tells you the version of the module. It is very convenient.

It does something similar to different single-line users, but it is a little smarter about error handling and can provide you with a version of more than one module at a time.

+3
Sep 25 '08 at 21:33
source share

I wrote a small script to report that: perlver .

This is a simple tool that will tell you which version of the module you installed and where the .pm file is located. It also ensures the module can be loaded successfully. This automatically converts '-,' /, or '\ To' ::, so you can use the path name or distribution name instead of the canonical module name.

The module is supposed to define $ VERSION. If the module does not detect $ VERSION, it will still tell you where the .pm file is located, so you can check it manually. You can also check several modules at once:

 $ perlver CPAN DBD-Pg Getopt::Long CPAN 1.7602 is /usr/lib/perl5/5.8.8/CPAN.pm DBD::Pg 1.49 is /usr/lib/perl5/vendor_perl/5.8.8/i686-linux/DBD/Pg.pm Getopt::Long 2.36 is /usr/lib/perl5/vendor_perl/5.8.8/Getopt/Long.pm 
+2
Sep 25 '08 at 20:33
source share

We have a perl system (/ usr / bin / perl) in Solaris 10, and the above solutions are useless. Some of them report that "module.pm is not installed", some of them have no way out.

Here is a useful code that can display all modules and their version.

 #!/usr/bin/perl use strict; use ExtUtils::Installed; my @modules; my $installed = ExtUtils::Installed->new(); if (scalar(@ARGV) > 0) { @modules = @ARGV; } else { @modules = $installed->modules(); } print "Module\tVersion\n"; foreach (@modules) { print $_ . "\t" . $installed->version($_) . "\n"; } 
+1
Feb 24 '14 at 2:37
source share

The easiest way to remember is the most reliable version for me:

 perl -e 'use Search::Elasticsearch; print $Search::Elasticsearch::VERSION;' 
+1
Nov 20 '17 at 16:52
source share

Also, for modules using Exporter.pm, you can get this information with this trick:

 perl -MSome::Module=99999 -ex Some::Module version 99999 required--this is only version 1.9205 at ... 

For modules that do not use Exporter.pm, a slightly longer trick reports the same information:

 perl -e'use Some::Module 99999' Some::Module version 99999 required--this is only version 1.9205 at ... 
0
25 Sep '08 at 20:43
source share

You can also take a look at App :: module :: version

 $ module-version The version of App::module::version in /home/yourself/perl5/lib/perl5 is 1.004 
0
Aug 7 '15 at 13:40
source share



All Articles