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 and put append a newline at the end of the output, and print does not.

But there's another difference: print and put converts its arguments to a string by calling the Str method on each item passed to, say uses the gist method instead. The gist 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.

Tags:

Raku