如何在 Perl 中增加带有前导零的值? [英] How do I increment a value with leading zeroes in Perl?
本文介绍了如何在 Perl 中增加带有前导零的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这与这个问题相同,但是使用 Perl!
It's the same question as this one, but using Perl!
我想迭代一个只有一个前导零的值.
I would like to iterate over a value with just one leading zero.
shell 中的等效项是:
The equivalent in shell would be:
for i in $(seq -w 01 99) ; do echo $i ; done
推荐答案
由于前导零很重要,所以大概您想将它们用作字符串,而不是数字.在这种情况下,有一个不涉及 sprintf 的不同解决方案:
Since the leading zero is significant, presumably you want to use these as strings, not numbers. In that case, there is a different solution that does not involve sprintf:
for my $i ("00" .. "99") {
print "$i\n";
}
这篇关于如何在 Perl 中增加带有前导零的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文