Perl版本字符串:为什么使用EVAL EXPR? [英] Perl version string: why use EVAL EXPR?

查看:167
本文介绍了Perl版本字符串:为什么使用EVAL EXPR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注意到了Catalyst.pl生成的这个.显然,这是某种无注释的hack.设置这样的版本字符串有什么好处?我什至无法弄清楚他们想做什么.

I just took notice to this generated by Catalyst.pl. It is obviously some sort of unannotated hack. What is the advantage of setting up a version string like this? I can't even figure out what they're trying to do.

our $VERSION = '0.01';
$VERSION = eval $VERSION;

推荐答案

版本号在Perl中很复杂. 这是一个很棒的概述血腥的细节.可能有很多使事情出错的微妙方法……

Version numbers are complex in Perl. Here's an excellent overview for those looking for the gory details. It might surprise you how many subtle ways there are to get things wrong...

尽管直接回答您的问题是,不同的事物期望使用不同的格式.对于CPAN,例如,您关心的是字符串的开发版本.对于运行时,您将它们视为一个数字.

The direct answer to your question though, is that different things expect different formats. For CPAN, you care about development versions for example, as a string. For runtime, you care about them as a number.

考虑$VERSION = "0.01_001"的情况. eval正确地将其转换为数字0.01001.

Consider the case of $VERSION = "0.01_001". eval converts it to the number 0.01001 correctly.

这篇关于Perl版本字符串:为什么使用EVAL EXPR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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