We have already seen several examples of the use of the print command in Perl. Now perhaps is a good time to see a more exact description of what it does.
The print command is very flexible and, in most cases, can do the same thing several different ways. In general, print takes a series of strings separated by commas, does any necessary variable interpolation, and then prints out the result. The string concatenation operator (.) is often used with print. All of the following lines yield the same output.
print "But these go to 11.\n"; $level = 11; print "But these go to ",$level,".\n"; print "But these go to $level.\n"; printf "But these go to %d.\n",$level; print "But these " . "go to ". $level.".\n"; print join(' ',("But","these","go","to","$level.\n"));
As you can see, the C-style printf command is available. However, because of Perl's ability to automatically interpolate numeric values to strings, printf is rarely needed.
There are, in fact, subtle performance issues that can be addressed with each of the methods in the example above. Wall and Schwartz's book, listed in the references, talks about these issues.
As seen in several of the previous examples, the print command also takes an optional filehandle argument.