Difference between print, put and say?
Handy Perl 6 FAQ: How and why do say, put and print differ?
The most obvious difference is that
say
andput
append a newline at the end of the output, andBut there's another difference:
put
converts its arguments to a string by calling theStr
method on each item passed to,say
uses thegist
method instead. Thegist
method, which you can also create for your own classes, is intended to create a Str for human interpretation. So it is free to leave out information about the object deemed unimportant to understand the essence of the object....
So, say is optimized for casual human interpretation, dd is optimized for casual debugging output and print and put are more generally suitable for producing output.
...
put $a
is like print $a.Str ~ “\n”
say $a
is like print $a.gist ~ “\n”
put
is more computer readable.say
is more human readable.
put 1 .. 8 # 1 2 3 4 5 6 7 8
say 1 .. 8 # 1..8
Learn more about .gist
here.
———
More accurately, put
and say
append the value of the nl-out
attribute of the output filehandle, which by default is \n
. You can override it, though. Thanks Brad Gilbert for pointing that out.