start page | rating of books | rating of authors | reviews | copyrights

Perl in a Nutshell

Perl in a NutshellSearch this book
Previous: Reference: split Chapter 5
Function Reference
Next: Reference: sqrt
 

sprintf

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
where the m and n are optional sizes whose interpretation depends on the type of field, and x is 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 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.


Previous: Reference: split Perl in a Nutshell Next: Reference: sqrt
Reference: split Book Index Reference: sqrt

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.