首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何获得已安装的Perl模块的版本和位置?

如何获得已安装的Perl模块的版本和位置?
EN

Stack Overflow用户
提问于 2009-12-17 15:27:10
回答 8查看 3.2K关注 0票数 5

有没有一种聪明的方法来检测系统中是否安装了某个Perl模块?我的老方法是编写一个Perl脚本,在这个脚本中,我唯一要做的就是使用模块。如果在运行检测脚本时没有发出任何声音,那么我知道模块已经安装,尽管我仍然不知道模块安装的版本和位置。

提前谢谢。

EN

Stack Overflow用户

发布于 2010-03-22 22:12:37

这是一个可以做到这一点的程序:

代码语言:javascript
运行
复制
#!/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";
票数 3
EN
查看全部 8 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1920045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档