File input/output

The printf function

Use the printf function to format your program output, e.g. to specify the number of decimal digits of floating point numbers or to emulate a tabular representation by inserting spaces between the printed values.

The general structure of the printf function is:

printf FILEHANDLE FORMAT, LIST

FORMAT contains a format control string, and LIST contains a list of variables that will be printed according to the format specified in FORMAT.

For example, to print $a and $b so that $a is printed in a 24 character field aligned to the left and $b is printed as a floating point value with 2 decimal places and a minimum total length of 5 characters, write:

$a= 1280;
$b= 5.205
printf FILEHANDLE "%-24s %5.2f\n", $a, $b;

The ouput will look as this:

.............................  # The dots will not be printed!
1280                     5.20

Table of Contents.
Previous | Next.