Working with files in Perl 6, as well as in many other languages, is done via file handles. You get the file handle as soon as you open a file; later, you use the handle to write to a file or to read from it. All the other operations, such as flushing a buffer or closing a file, are also performed via the handle.
Working with files and directories
Opening a file
To open a file, use the open function (it is supplied by the IO role but can be used as a simple built-in function). It takes the path to the file and a number of optional parameters. The return value is a file handle, as shown:
my $fh = open '/etc/passwd';
By default, the file is opened in the read-only mode. It is possible to pass the mode name explicitly...