A Better print

The print function is a very simple output function; it provides almost no formatting capability. To have fine-grained control over printing such as left and right alignment, decimal precision, and fixed-width output, you can use the Perl printf function. The printf function was borrowed (almost verbatim) from the C programming language, but other languages have a similar function, such as BASIC's print using function. The syntax for printf is as follows:

printf formatstring, list
printf filehandle formatstring, list
					

The formatstring is a string that describes the format of the output, which is described shortly. The list is a list of values that you want printf to display—similar to the print statement. Normally, printf displays ...

Get Sams Teach Yourself Perl in 24 Hours 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.