On 10/9/18 6:22 AM, Curt Tilmes wrote:
On Tue, Oct 9, 2018 at 8:49 AM ToddAndMargo via perl6-users
<perl6-us...@perl.org <mailto:perl6-us...@perl.org>> wrote:
I am not getting anywhere with `.lines`. Read the whole thing in the
first line.
$ p6 'my $fh=open "/home/linuxutil/WhoIsMySub.pl6", :r; while my $f =
$fh.lines { say "$f\n"}; $fh.close;'
.lines() creates Seq (https://docs.perl6.org/type/Seq) that is a lazy
list of all the lines in the file.
Your while loop calls it once, which makes that Seq, Inside your first
loop, which prints it, the Stringify iterates the Seq, printing all the
lines.
The second call to .lines() returns nothing because you're now at eof,
no more lines.
Note the Seq that .lines returns itself is lazy. It doesn't
(necessarily) have all the lines, just the capability to get them.
As you iterate the Seq, it pulls in all the lines.
Curt
Hi Curt,
I was thinking that .lines read them one at a time.
Thank you!
-T
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~