> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/perl6-rosettacode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/perl6-rosettacode/programming_tasks/r/read_a_file_line_by_line.md).

# Read a file line by line

The lines method is lazy so the following code does indeed read the file line by line, and not all at once.

```perl
for open('test.txt').lines
{
  .say
}
```

In order to be more explicit about the file being read on line at a time, one can write:

```perl
my $f = open 'test.txt';
while my $line = $f.get {
    say $line;
}
```
