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
printfandfprintffunctions, except that the*field width specifier is not supported. The function is exactly equivalent to:
print filehandle sprintf(format, list);
printfandsprintfuse the same format syntax, butsprintfonly 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, andxis the type of field. The optionalmgives the minimum field width for appropriate field types (negativemleft-justifies). The.ngives 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 cCharacter dDecimal integer eExponential format floating-point number EExponential format floating-point number with uppercase E fFixed-point format floating-point number gFloating-point number, in either exponential or fixed decimal notation GLike gwith uppercase E (if applicable)ldLong decimal integer loLong octal integer luLong unsigned decimal integer lxLong hexadecimal integer oOctal integer sString uUnsigned decimal integer xHexadecimal integer XHexadecimal integer with uppercase letters pThe Perl value's address in hexadecimal nSpecial value that stores the number of characters output so far into the next variable in the parameter list