How can I find the version of an installed Perl mo

2019-01-16 07:27发布

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
}

12条回答
戒情不戒烟
2楼-- · 2019-01-16 07:35

VERSION is a UNIVERSAL method of all Perl classes. You can use it to get the module version (if it has been set which it usually has).

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

perl -le 'eval "require $ARGV[0]" and print $ARGV[0]->VERSION' Some::Module
查看更多
3楼-- · 2019-01-16 07:35

Easiest to remember and most robust version for me:

perl -e 'use Search::Elasticsearch; print $Search::Elasticsearch::VERSION;'
查看更多
闹够了就滚
4楼-- · 2019-01-16 07:36

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

function perlmodver {
    perl -M$1 -e 'print $ARGV[0]->VERSION . "\n"' $1
} 
查看更多
对你真心纯属浪费
5楼-- · 2019-01-16 07:47

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

Here is the code which is helpful, which can list 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";

}
查看更多
乱世女痞
6楼-- · 2019-01-16 07:49

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
查看更多
做个烂人
7楼-- · 2019-01-16 07:50

Check out the pmtools scripts on CPAN. If you're using a Debian(-based) distro, there's also a handy pmtools package. This includes a script "pmvers" that tells you a module's version. It's quite handy.

It does something similar to the various one-liners folks posted, but it's a bit smarter about error handling, and can give you the version of more than one module at once.

查看更多
登录 后发表回答