如何在 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";
}