Chapter 27. Formatted Printing

printf and sprintf format a list of values according to a format string that may use the following conversions:


A percent sign.


An unsigned number (binary).


The character corresponding to the ordinal value.


A signed integer.


A floating-point number (scientific notation).


A floating-point number (fixed decimal notation).


A floating-point number (%e or %f notation).


A synonym for %d.


The number of characters formatted so far is stored into the corresponding variable in the parameter list.


An unsigned integer, in octal.


A pointer (address in hexadecimal).


A string.


An unsigned integer (decimal).


An unsigned integer (hexadecimal).


An obsolete synonym for %ld.


Like %e, but using an uppercase E.


An obsolete synonym for %f.


Like %g, but with an uppercase E (if applicable).


An obsolete synonym for %lo.


An obsolete synonym for %lu.


Like %x, but using uppercase letters.

The following flags can be put between the % and the conversion letter:


Prefix a positive number with a space.


Prefix a positive number with a plus sign.

Left-align within the field.


Use zeroes instead of spaces to right-align.


With o, b, x, and X: prefix a nonzero number with 0, 0b, 0x, or 0X.


Minimum field width.


For a floating-point number, the number of digits after the decimal point. For a string, the maximum length. For an integer, the minimum width.


Interpret integer as short or unsigned short according to the C type.


Interpret integer as long or unsigned ...

Get Perl Pocket Reference, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.