Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between print, put and say?

Tags:

raku

In Perl 6, what is the difference between print, put and say?

I can see how print 5 is different, but put 5 and say 5 look the same.

like image 808
Stefanus Avatar asked Mar 31 '18 11:03

Stefanus


People also ask

Does puts print a n?

But we must also print a newline manually. One major difference between print and puts is that print does not append a newline automatically. Newlines must be manually added while using the print method. In puts method, the newline is automatically appended.

What is the difference between say and print in Perl?

The only difference between print and say is that the say function adds a new line at the end of its output. So, if I come down here to our say function, and I just copy and paste this a few times, when I run it, you notice that the output of each say function is on its own line.

What is difference with print and in Python?

print just shows the human user a string representing what is going on inside the computer. The computer cannot make use of that printing. return is how a function gives back a value. This value is often unseen by the human user, but it can be used by the computer in further functions.

What can we use instead of printf in C?

You could use puts() or putchar() . puts("Hello, world!\ n"); There's a also fputs() , putc() , and fputc() if you want/need to specify a FILE* to write to.


2 Answers

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.

like image 83
Christopher Bottoms Avatar answered Nov 06 '22 07:11

Christopher Bottoms


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.

...

like image 30
mr_ron Avatar answered Nov 06 '22 07:11

mr_ron