Documentation for routine print

Documentation for routine print, assembled from the following types:

class Mu

From Mu

(Mu) method print

multi method print(--> Bool:D)

Prints value to $*OUT after stringification using .Str method without adding a newline at end.

"abc\n".print;          # RESULT: «abc␤» 

role IO

From IO

(IO) sub print

Print the given text on $*OUT (standard output), e.g.:

print "Hi there!\n";   # Hi there! 

Note that the print function does not (in contrast to some other languages) append a newline character to the text. Thus the following code

print "Hi there!";
print "How are you?";
print (0..101).list;


Hi there!How are you?0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101

To print text implicitly including the trailing newline character, use put.

class IO::Handle

From IO::Handle

(IO::Handle) method print

Defined as:

method print(**@text --> True)

Writes the given @text to the handle, coercing any non-Str objects to Str by calling .Str method on them. See write to write bytes.

Attempting to call this method when the handle is in binary mode will result in X::IO::BinaryMode exception being thrown.

my $fh = 'path/to/file' :w;
$fh.print: 'some text';

class IO::CatHandle

From IO::CatHandle

(IO::CatHandle) method print

Defined as:

multi method print(|)

In Rakudo, the IO::CatHandle type overrides this method to throw X::NYI exception. If you have a good idea for how this method should behave, tell Rakudo developers about it!

role IO::Socket

From IO::Socket

(IO::Socket) method print

method print(IO::Socket:D: Str(Cool$string)

Writes the supplied string to the socket, thus sending it to other end of the connection. The binary version is method write.

Fails if the socket is not connected.

class IO::Socket::Async

From IO::Socket::Async

(IO::Socket::Async) method print

method print(Str $str --> Promise)

Attempt to send $str on the IO::Socket::Async that will have been obtained indirectly via connect or listen, returning a Promise that will be kept with the number of bytes sent or broken if there was an error sending.

class Proc::Async

From Proc::Async

(Proc::Async) method print

method print(Proc::Async:D: Str(Any$str:$scheduler = $*SCHEDULER)

Write the text data in $str to the standard input stream of the external program, encoding it as UTF-8.

Returns a Promise that will be kept once the data has fully landed in the input buffer of the external program.

The Proc::Async object must be created for writing (with, $path, @args)). Otherwise an X::Proc::Async::OpenForWriting exception will the thrown.

start must have been called before calling method print, otherwise an X::Proc::Async::MustBeStarted exception is thrown.