You were probably only one character away at one point...unfortunately, then you jumped the wrong direction. :-) The format you were looking for is "%04d", which is equivalent to the version in perlfaq4 if $padlen is equal to 4.
Your mistake was that you replaced the string "pad_len" with an integer, rather than replacing the variable $pad_len (which is inserted in the string in the FAQ using braces so that perl knows you're not looking for the variable $pad_lend). Since this means that instead of inserting "4" into your string, you're inserting the value of $4, which happens to be empty, you get no padding, which I presume is the error you saw.
In reply to Re^3: Left padding a number with zeros: PerlFaq method didn't work for me.
by ChemBoy
in thread Left padding a number with zeros: PerlFaq method didn't work for me.
by JCHallgren
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |