有没有一种聪明的方法来检测系统中是否安装了某个Perl模块?我的老方法是编写一个Perl脚本,在这个脚本中,我唯一要做的就是使用模块。如果在运行检测脚本时没有发出任何声音,那么我知道模块已经安装,尽管我仍然不知道模块安装的版本和位置。
提前谢谢。
发布于 2010-03-22 22:12:37
这是一个可以做到这一点的程序:
#!/usr/bin/perl
# testmod - test to see if a module is available
use strict;
use warnings;
my $mod = (shift @ARGV) || die "usage: $0 module\n";
# convert module-name to path
my $file = $mod;
$file =~ s{::}{/}gsmx;
$file .= '.pm';
# Pull in the module, if it exists
eval { require $file }
    or die "can't find module $mod\n";
# Get the version from the module, if defined
my $ver;
{ no strict 'refs';
    $ver = ${$mod . "::VERSION"} || 'UNKNOWN';
}
# And its location
my $from = $INC{$file};
print "module $mod is version $ver loaded from $from\n";https://stackoverflow.com/questions/1920045
复制相似问题