Up to now, we've relied on the
The entire story about these Perl output features is beyond the scope of this book, but I'll tell you just enough to give you an idea of how they can be used.
printf function is
printf function is taken from the C
language function of the same name. Here's an example of a
my $first = '3.14159265'; my $second = 76; my $third = "Hello world!"; printf STDOUT "A float: %6.4f An integer: %-5d and a string: %s\n", $first, $second, $third;
This code snippet prints the following:
A float: 3.1416 An integer: 76 and a string: Hello world!
The arguments to the
a format string, followed by a list of values that are printed as
specified by the format string. The format string may also contain any text
along with the directives to print the list of values. (You may also specify an
optional filehandle in the same manner you would in a
directives consist of a percent sign followed by a required
conversion specifier, which in the example includes
f for floating point,
s for string. The conversion specifier indicates what kind of data is in the variable to be printed. ...