Name
sprintf
Synopsis
sprintf format, list
Returns a string formatted by the printf
conventions. The
format
string contains text with
embedded field specifiers into which the elements of
list
are substituted, one per field.
Field specifiers are roughly of the form:
%m.nx
in which m
and
n
are optional sizes with
interpretation that depends on the type of field, and
x
is one of the following:
Code | Meaning |
---|---|
| Percent sign |
| Character |
| Decimal integer |
| Exponential format floating-point number |
| Exponential format floating-point number with uppercase E |
| Fixed-point format floating-point number |
| Floating-point number, in either exponential or fixed decimal notation |
| Like |
| Long decimal integer |
| Long octal integer |
| Long unsigned decimal integer |
| Long hexadecimal integer |
| Octal integer |
| String |
| Unsigned decimal integer |
| Hexadecimal integer |
| Hexadecimal integer with uppercase letters |
| The Perl value’s address in hexadecimal |
| Special value that stores the number of characters output so far into the next variable in the parameter list. |
m
is typically the minimum length
of the field (negative for left-justified), and
n
is precision for exponential formats
and the maximum length for other formats. Padding is typically
done with spaces for strings and zeroes for numbers. The *
character as a length specifier is not
supported.
Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.