Perl uses the
printf functions to write to standard output. Let's look at how they are used.
We've already used
$a = print("hello ", "world", "\n");
would be another way to say
hello world. The return value of
$a in this case would usually be 1.
print (2+3),"hello"; # wrong! prints 5, ignores "hello" print ((2+3),"hello"); # right, prints 5hello print 2+3,"hello"; # also right, prints 5hello
You may wish a little more control over your output than
printf function. Fear not: Perl provides a comparable operation with the same name.
printf function takes a list of arguments (enclosed in optional parentheses, like the
printf function, you should probably check out the manpage for printf (3) or perlfunc (1), if you have one, or look at the description in Chapter 3 of Programming Perl.
As an example, however
printf "%15s %5d %10.2f\n", $s, $n, $r;
$s in a 15-character field, then space, then
$n as a decimal integer in a 5-character field, then another space, then
$r as a floating-point value with 2 decimal places in a 10-character field, and finally a newline.