Perl比较版本号5.1< 5.10 [英] Perl compare version numbers 5.1 < 5.10
本文介绍了Perl比较版本号5.1< 5.10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在比较2个版本时遇到困难.如果我们有5.1和5.10,则5.1应该小于5.10.我知道十进制应为5.01和5.10.但是有没有一种方法可以使用5.1和5.10进行比较?
I am having difficulties in comparing 2 versions. If we have 5.1 and 5.10 then 5.1 should be smaller than 5.10. I know that in decimal it should read 5.01 and 5.10. But is there a way to compare it using 5.1 and 5.10?
perl -e 'use warnings; use version; if (version->parse("5.1") < version->parse("5.10")) { print "ok"; }'
推荐答案
version
模块文档显示了如何执行此操作:
The version
module documentation shows how to do this:
print version->declare('5.1')->numify; # 5.00100
print version->declare('5.10')->numify; # 5.01000
这篇关于Perl比较版本号5.1< 5.10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文