Perl:如何获取“使用版本”数字
是否有一个特殊的变量或函数可以在运行脚本时为我提供 use VERSION
的数量(在本例中为 5.12.0
)?
#!/usr/bin/env perl
use warnings;
use 5.12.0;
Is there a special variable or a function which gives me the number of use VERSION
(in this case 5.12.0
) when running the script?
#!/usr/bin/env perl
use warnings;
use 5.12.0;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚快速检查了
feature.pm
代码 - 版本本身没有存储在任何地方。亚历克斯的回答已经展示了如何测试通话产生的特定功能。另请注意,
use VERSION
可以在多个位置调用(例如在模块中)。一种假设的选择是覆盖
use
并在某处记录版本号以供检查。编辑:在钩子方向上进行一些探索:
这个有限的示例报告了指定的版本,但对于真正的使用,它必须更加强大。
I just quickly checked
feature.pm
code - the version itself is not stored anywhere. Alex's answer already showed how to test particular features that results from the call.Also note that
use VERSION
can be called on several places (in modules for instance).One hypothetical option would be to override
use
and record the version number somewhere for inspection.Edit: Some poking in the hook direction:
This limited example reports the version specified, but for real use it would have to be much more robust.
您可以在编译时查看提示变量 (
${^H}
)(龙潜伏的位置)并查看提示哈希 (%{^H})(龙潜伏的位置,但以公开记录的方式),这会让您知道启用了哪些特定功能。我不知道如何计算是否需要特定的功能包或所有给定的功能:You can, during compile time, poke about in the hints variable (
${^H}
) (where dragons lurk) and look into the hints hash (%{^H}) (where dragons lurk, but in a public documented sort of way), this will let you know which specific features are enabled. I don't know how to work out if specifically a feature bundle, or all given features, were requested:其中任何一个都会为您提供解释器的版本:
那些将是>比“使用”行上的内容更重要:如果您需要确切的字符串,请硬着头皮将其粘贴到变量中,如下所示:
Either one of these gives you the version of the interpreter:
Those will be > than what you have on the "use" line: if you need that exact string, bite the bullet and stick it in a variable as in: