print and say
print writes text exactly as given, and say does the same but adds a newline.
In this page:
print and say
print outputs a list of values with no separator and no automatic newline. The say function, enabled with use feature say or use v5.10, appends a newline for you. Both can print to a filehandle such as STDERR when you put the handle first, with no comma after it.
Note:
Set $, to change the separator between print items and $\ to add something at the end of each print.
Example: print and say
use strict;
use warnings;
use feature 'say';
print "one", "two", "three";
print "\n";
say "hello";
say "a", "b", "c";
{
local $, = "-";
say "x", "y", "z";
}
print STDOUT "to STDOUT\n";
# Output:
# onetwothree
# hello
# abc
# x-y-z
# to STDOUT
Login to try C/C++/Java/PHP code in the editor
Common Mistakes
- Forgetting that print adds no newline
- Calling say without enabling the feature
- Putting a comma after the filehandle in print STDERR, "text"
Chapter Summary
- print adds no newline
- say adds a newline
- say needs use feature say
- No comma after a filehandle
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: