September 2017
Beginner
402 pages
9h 52m
English
We will start with the simple print function. Basically, its usage is obvious. It prints the text to the stream. In the case of standard output, use the bare print function or the $*IN.print method. If you work with a file, use its file handle.
The following program creates a file named hello.txt and writes a string to it.:
my $fh = open 'hello.txt', :w; # Open a file for writing
$fh.print('Hello, World'); # Print to the file
$fh.close; # Close the file so that the data is saved
If the file already exists, it will be re-written, and all previous contents will be lost. Use the :a append mode if you need to append new output to an existing file:
my $fh = open 'hello.txt', :a; # Open in append mode $fh.print('!'); # Now the ...Read now
Unlock full access