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

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

问题描述

我写了一个 Perl 脚本,我只想给每个人,为此,我计划编写一个 bash 脚本,用于测试用户的环境并确定该环境是否能够运行 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.

我想测试以下内容:

  1. 该系统中是否安装了 Perl
  2. Perl 应该有 5 或更高版本
  3. 模块 JSON::Any 是否可用

任何建议将不胜感激:-)

Any suggestion would greatly appreciated :-)

推荐答案

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

我经常使用 '${PERL:-perl}' 和类似的结构来识别命令(对于 awknawkgawk; troff vs groff; etc).

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

如果您想测试 JSON::Any 的版本,请改为捕获命令的输出.如果您想测试 Perl 的版本,请添加use 5.008009;"或您认为合理的任何数字.(就在不久之前,他们终于从一个正在运行的 NFS 挂载文件系统中删除了 Perl 4——但这并不是机器上唯一的 Perl——至少,在过去十年或更长时间里不是!)

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 的可用性、它的版本和所需模块的存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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