in reply to printf numification

Are you sure "%4.4d" is legal? (Update: perlfunc says it's only legal for floating point formatters.) Using a proper formatting string, it works fine for me in ActivePerl 5.6.1 build 633:

>perl -le "printf('%04d', '42a');" 0042

Replies are listed 'Best First'.
Re^2: printf numification
by YuckFoo (Abbot) on Sep 27, 2004 at 18:28 UTC
    My take on the docs is that '%4.4d' is legal. Maybe not the most straight forward way, but legal. I think I regularly abuse it this way, a mental hangover from the 's' format I think.

    Anyway, no matter, '%04d' doesn't numify here either.

    Yuck%4.4d

    Update: From perldoc -f sprintf:

    Perl permits the following universally-known flags between the "%" and the conversion letter: space prefix positive number with a space + prefix positive number with a plus sign - left-justify within the field 0 use zeros, not spaces, to right-justify # prefix non-zero octal with "0", non-zero hex with "0x" number minimum field width .number "precision": digits after decimal point for floating-point, max length for string, minimum length for integer