September 2017
Beginner
402 pages
9h 52m
English
Reading from the file only makes sense when there is data left in it. To check if the file or stream still contains data, use the eof method, which returns False when the end of file is reached:
my $fh = open 'data.txt';
if $fh && !$fh.eof { # Only if file exists and has something to read
my $line = $fh.get;
say $line;
}