Appendix A. sprintf
For whatever reason, most Perl books don't actually document the sprintf and printf operators. Instead, they say something like "check the man page for sprintf(3) ." I've always thought it would be handy if at least one of the Perl books on my shelf contained a quick reference to sprintf , thoughso here it is.
The arguments to Perl's sprintf operator are a format string and a list of values to be formatted. The format string contains conversion specifiers, which begin with the percent sign character % and end with one of several characters like d , f , or x . The specifiers are replaced with their corresponding formatted values, and the result is a string:
The printf operator works like sprintf , except that it sends the formatted string to standard output, or to some other filehandle if specified:
That's all there is to it, except for a description of sprintf 's conversion specifiers. The rest of this Appendix is a summary of the conversion specifiers and their features.