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 xis one of 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.

m is typically the minimum length of the field (negative for left-justified), and nis 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.