Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I increment a value with leading zeroes in Perl?

Tags:

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.

The equivalent in shell would be:

for i in $(seq -w 01 99) ; do echo $i ; done
like image 946
Falken Avatar asked Feb 09 '10 09:02

Falken


People also ask

What does $$ mean in Perl?

Normally the $$ is used to print the current process ID. print $$;

What does 0 mean in Perl?

0 means false in Perl (and other languages related to C). For the most part, that's a reasonable behavior.


1 Answers

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";
}
like image 62
Porculus Avatar answered Dec 14 '22 11:12

Porculus