Search code examples
perlsequenceleading-zero

Perl sequence of numbers with leading zeros


Is there some easy way (without sprintf and, of course, printf) to get a list of (001, 002, ... 100) in Perl? In bash it was something like seq -w 1 100. What about Perl?


Solution

  • you mean like this?

    for ('001'..'100') {
        print "$_\n";
    }
    

    .. in a range, returns a list of values counting by ones, from the left value to the right value.

    For more details about how to use range, please refer to: Perldoc range operator and this link