September 2017
Beginner
402 pages
9h 52m
English
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 using the named arguments. The above example is equivalent to the following code:
my $fh = open '/etc/passwd', :r;
The following table lists the possible modes for opening a file:
| Parameter | Description |
| :r | Read-only mode. This is the default mode. |
| :w | Write-only mode. Creates a file if it does not exist and overwrites it otherwise. |
| :rw | Read-write mode. Creates a file ... |
Read now
Unlock full access