问题描述
我对5.10.0之前的文档与较新的版本之间的建议存在冲突感到有些困惑模块. Perl最佳做法可以很清楚地看出版本字符串('v1.0.3')是错误的,并且是一个应该指定如下版本:
I'm a bit confused by conflicting advice between pre-5.10.0 documents and the more recent version module. Perl Best Practices makes it pretty clear that version strings ('v1.0.3') are bad and one is supposed to specify a version as follows:
use version; our $VERSION = qv('1.0.3');
但是版本模块说我们要返回使用版本字符串:
but the version module says that we're back to using version strings:
use version 0.77; our $VERSION = qv("v1.2.3");
我们退步了,还是背后有原因?
Have we regressed, or is there a reason behind this?
推荐答案
您从 Perl最佳实践中引用的报价不太正确.具体来说,裸形式的vstrings
Your quote from Perl Best Practices is not quite right. Specifically, bare vstrings of the form
our $VERSION = v1.0.3;
不鼓励
.在最新版本的version.pm中,建议使用真实的字符串:
are discouraged. In the latest version of version.pm, the recommendation is to use true strings:
use version 0.77; our $VERSION = qv("v1.2.3"); # shorthand
已添加此功能以提高可读性,同时特别避免描述此处.
This functionality has been added to aid readability, while specifically avoid the traps of bare strings described here.
如您链接到的文档页面所述,您可以使用版本,而无需使用Perl 5.10中的内置逻辑在前面加上'v':
As the doc page you linked to says, you can use versions without the pre-pending 'v' using built-in logic in Perl 5.10:
因此,您的问题的答案是:如果要编写使用version.pm的新代码,请使用新的"v1.0.3"语法.如果那是您的旧代码编写方式,或者不想显式依赖module.pm,请坚持使用纯数字.
So the answer to your question is: use the new "v1.0.3" syntax if you are writing new code that uses version.pm. Stick to a plain number if that is how your old code was written, or if you don't want to depend explicitly on module.pm.
这篇关于如何在Perl中指定软件包版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!