Returns a string formatted by the usualprintf conventions of the C library functionsprintf. Seesprintf(3) orprintf(3) on your system for an explanation of the general principles.
Perl does its ownsprintf formatting--it emulates the C functionsprintf, but it doesn't use it (except for floating-point numbers, and even then only the standard modifiers are allowed). As a result, any non-standard extensions in your localsprintf are not available from Perl.
Perl'ssprintf permits the following universally-known conversions:
%%a percent sign%ca character with the given number%sa string%da signed integer, in decimal%uan unsigned integer, in decimal%oan unsigned integer, in octal%xan unsigned integer, in hexadecimal%ea floating-point number, in scientific notation%fa floating-point number, in fixed decimal notation%ga floating-point number, in %e or %f notationIn addition, Perl permits the following widely-supported conversions:
%Xlike %x, but using upper-case letters%Elike %e, but using an upper-case "E"%Glike %g, but with an upper-case "E" (if applicable)%ban unsigned integer, in binary%pa pointer (outputs the Perl value's address in hexadecimal)%nspecial: *stores* the number of characters output so far into the next variable in the parameter listFinally, for backward (and we do mean "backward") compatibility, Perl permits these unnecessary but widely-supported conversions:
%ia synonym for %d%Da synonym for %ld%Ua synonym for %lu%Oa synonym for %lo%Fa synonym for %fPerl permits the following universally-known flags between the% and the conversion letter:
space prefix positive number with a space+ prefix positive number with a plus sign- left-justify within the field0 use zeros, not spaces, to right-justify# prefix non-zero octal with "0", non-zero hex with "0x"number minimum field width.number "precision": digits after decimal point for floating-point, max length for string, minimum length for integerl interpret integer as C type "long" or "unsigned long"h interpret integer as C type "short" or "unsigned short" If no flags, interpret integer as C type "int" or "unsigned"There are also two Perl-specific flags:
V interpret integer as Perl's standard integer type v interpret string as a vector of integers, output as numbers separated either by dots, or by an arbitrary string received from the argument list when the flag is preceded by C<*>Where a number would appear in the flags, an asterisk (*) may be used instead, in which case Perl uses the next item in the parameter list as the given number (that is, as the field width or precision). If a field width obtained through* is negative, it has the same effect as the- flag: left-justification.
Thev flag is useful for displaying ordinal values of characters in arbitrary strings:
printf "version is v%vd\n", $^V;# Perl's versionprintf "address is %*vX\n", ":", $addr;# IPv6 addressprintf "bits are %*vb\n", " ", $bits;# random bitstringIfuse locale is in effect, the character used for the decimal point in formatted real numbers is affected by the LC_NUMERIC locale. Seeperllocale.
If Perl understands "quads" (64-bit integers) (this requires either that the platform natively support quads or that Perl be specifically compiled to support quads), the characters
d u o x X b i D U Oprint quads, and they may optionally be preceded by
ll L qFor example
%lld %16LX %qoYou can find out whether your Perl supports quads viaConfig:
use Config;($Config{use64bitint} eq 'define' || $Config{longsize} == 8) &&print "quads\n";If Perl understands "long doubles" (this requires that the platform support long doubles), the flags
e f g E F Gmay optionally be preceded by
ll LFor example
%llf %LgYou can find out whether your Perl supports long doubles viaConfig:
use Config;$Config{d_longdbl} eq 'define' && print "long doubles\n";Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.
The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.