put
ErrorsCollection

put

Synthesised documentation from type/independent-routines type/IO/Socket type/Mu type/Proc/Async type/IO/Handle type/IO/CatHandle

From type/independent-routines

See Original text in context

multi sub put()
multi sub put(**@args --> True)
multi sub put(Junction:D --> True)
multi sub put(Str:D \x)
multi sub put(\x)

Same as print, except it uses print-nl (which prints a newline, by default) at the end. Junction arguments autothread and the order of printed strings is not guaranteed.

put "Hi there!\n";   # OUTPUT: «Hi there!␤␤» 
put "Hi there!";     # OUTPUT: «Hi there!␤» 
put [123];       # OUTPUT: «1 2 3␤» 
put "Hello" | "Goodbye"# OUTPUT: «Hello␤Goodbye␤»

By itself, put() will print a new line

put "Hey"put(); put("Hey"); # OUTPUT: «Hey␤␤Hey␤»

but please note that we have used parentheses after put. Without these parentheses, it will throw an exception (with version 6.d and after). It will also raise an exception if it's used that way before for; use the method form .put instead.

.put for <1 2 3>;             # OUTPUT: «1␤2␤3␤»

From type/IO/Socket

See Original text in context

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

Writes the supplied string, with a \n appended to it, to the socket, thus sending it to other end of the connection.

Fails if the socket is not connected.

From type/Mu

See Original text in context

multi method put(--> Bool:D)

Prints value to $*OUT, adding a newline at end, and if necessary, stringifying non-Str object using the .Str method.

"abc".put;              # OUTPUT: «abc␤»

From type/Proc/Async

See Original text in context

method put(Proc::Async:D: \x|c)

Does a .join on the output, adds a newline, and calls .print on it. Will throw if it's not started, or not open for writing.

From type/IO/Handle

See Original text in context

multi method put(**@text --> True)
multi method put(Junction:D --> True)

Writes the given @text to the handle, coercing any non-Str objects to Str by calling .Str method on them, and appending the value of :$nl-out at the end. Junction arguments autothread and the order of printed strings is not guaranteed.

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

my $fh = 'path/to/file'.IO.open: :w;
$fh.put: 'some text';
$fh.close;

From type/IO/CatHandle

See Original text in context

multi method put(|)

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