如何检查Perl中,所需的模块其版本和presence的可用性? [英] How to check availability of Perl, its version and presence of a required module?

查看:104
本文介绍了如何检查Perl中,所需的模块其版本和presence的可用性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个Perl脚本,我只想把它给每个人,结果
对于我计划写它是用来测试结果bash脚本
的使用者和环境发现环境是否能够搜索
运行Perl脚本。

我要测试的东西像搜索


  1. 不管是Perl已经安装在系统中搜索

  2. Perl的应该有第5版或以上结果

  3. 模块是否JSON ::任何可用搜索结果

任何建议,将大大AP preciated: - )


解决方案

 如果perl的-MJSON ::任何-e打印$ JSON ::任何::版本\\ N' >的/ dev / null的2  - ;&放大器; 1
然后:OK
其他回声无法找到一个Perl使用JSON ::任何已安装的1>和2
     1号出口
科幻

我经常用 $ {PERL:-perl} 和类似的结构来识别命令( AWK VS NAWK GAWK ; 的troff VS groff的;等)

如果你想测试JSON版本::任何,捕获,而不是命令的输出。
如果你想测试的Perl的版本中,添加使用5.008009; '或任何号码,你认为这是明智的。 (这是不久前,他们终于在工作NFS文件系统中的一个拆除Perl的4 - 但这不是机器上的唯一Perl的 - 至少,不是在过去十年或更多!)

I have written a perl script , I just want to give it to every one ,
for that I planned to write a bash script which is used to test the
environment of a user and find whether that environment is capable
of running the perl script.

I want to test the things like

  1. Whether Perl has installed in that system
  2. Perl should have the version 5 or more
  3. Whether the module JSON::Any is available

Any suggestion would greatly appreciated :-)

解决方案

if perl -MJSON::Any -e 'print "$JSON::Any::VERSION\n"' >/dev/null 2>&1
then : OK
else echo "Cannot find a perl with JSON::Any installed" 1>&2
     exit 1
fi

I often use '${PERL:-perl}' and similar constructs to identify the command (for awk vs nawk or gawk; troff vs groff; etc).

If you want to test the version of JSON::Any, capture the output from the command instead. If you want to test the version of Perl, add 'use 5.008009;' or whatever number you think is sensible. (It wasn't so long ago that they finally removed Perl 4 from one of the NFS-mounted file systems at work - but that was not the only Perl on the machine - at least, not in the last decade or more!)

这篇关于如何检查Perl中,所需的模块其版本和presence的可用性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆