Precision in an integer makes not so much sense. It gets repurposed for a slightly different meaning. From the perldoc on sprintf one can find this:

For integer conversions, specifying a precision imp +lies that the output of the number itself should be zero +-padded to this width, where the 0 flag is ignored: printf '<%.6d>', 1; # prints "<000001>" printf '<%+.6d>', 1; # prints "<+000001>" printf '<%-10.6d>', 1; # prints "<000001 >" printf '<%10.6d>', 1; # prints "< 000001>" printf '<%010.6d>', 1; # prints "< 000001>" printf '<%+10.6d>', 1; # prints "< +000001>" printf '<%.6x>', 1; # prints "<000001>" printf '<%#.6x>', 1; # prints "<0x000001>" printf '<%-10.6x>', 1; # prints "<000001 >" printf '<%10.6x>', 1; # prints "< 000001>" printf '<%010.6x>', 1; # prints "< 000001>" printf '<%#10.6x>', 1; # prints "< 0x000001>"

Either drop the precision portion or set it to 2. There are other options which provide the proper output but maybe shouldn't.

printf "<%.2d>\n", 5; printf "<%02.2d>\n", 4; printf "<%02d>\n", 3; printf "<%02.0d>\n", 2; printf "<%0.2d>\n", 1; printf "<%1.2d>\n", 0;
prints:
<05> <04> <03> < 2> <01> <00>

The first three options there make sense to me, although the first in an ugly sort of way. The fourth, as you're finding out, is having the precision portion ignored as per the documentation. The fifth and sixth I would consider undocumented behavior and subject to change.

Update:
In the Perl 5.8.8 documentation, it says something similar, and I consider the behavior of padding to 2 in the %02.0d case to be a bug in that version.:

For integer conversions, specifying a precision imp +lies that the output of the number itself should be zero-padded to th +is width: printf ’<%.6x>’, 1; # prints "<000001>" printf ’<%#.6x>’, 1; # prints "<0x000001>" printf ’<%-10.6x>’, 1; # prints "<000001 >"

In reply to Re: output format changed perl5.8 --> perl 5.10? by mr_mischief
in thread output format changed perl5.8 --> perl 5.10? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.