Reference: printf
Author: Ellen Siever, Stephen Spainhour & Nathan Patwardhan
Date: 1999-07-02T01:36:51Z

#

| Chapter 5 Function Reference |

## printf

    printf [filehandle] format, list

Prints a formatted string of the elements in list to filehandle or, if omitted, the currently selected output filehandle. This is similar to the C library's `printf` and `fprintf` functions, except that the `*` field width specifier is not supported. The function is exactly equivalent to:

>     print filehandle sprintf(format, list);

`printf` and `sprintf` use the same format syntax, but `sprintf` only returns a string; it doesn't print to a filehandle. The format string contains text with embedded field specifiers into which the the elements of list are substituted in order, one per field. Field specifiers follow the form:

>     %m.nx

A percent sign begins each field, and `x` is the type of field. The optional `m` gives the minimum field width for appropriate field types (negative `m` left-justifies). The `.n` gives the precision for a specific field type, such as the number of digits after a decimal point for floating-point numbers, the maximum length for a string, and the minimum length for an integer.

Field specifiers (`x`) may be the following:

Code | Meaning
--- | ---
`%` | Percent sign
`c` | Character
`d` | Decimal integer
`e` | Exponential format floating-point number
`E` | Exponential format floating-point number with uppercase E
`f` | Fixed-point format floating-point number
`g` | Floating-point number, in either exponential or fixed decimal notation
`G` | Like `g` with uppercase E (if applicable)
`ld` | Long decimal integer
`lo` | Long octal integer
`lu` | Long unsigned decimal integer
`lx` | Long hexadecimal integer
`o` | Octal integer
`s` | String
`u` | Unsigned decimal integer
`x` | Hexadecimal integer
`X` | Hexadecimal integer with uppercase letters
`p` | The Perl value's address in hexadecimal
`n` | Special value that stores the number of characters output so far into the next variable in the parameter list

Reference: print |  | Reference: prototype