Perl 6 Perl 6 Lists and Arrays vivified #22

Perl 6 lazy list example #1

Perl 6 version, using lazy lists:

use v6;

# open file.txt for reading
my $fh = open('file.txt');

# read lines until blank found
for $fh.lines { last if /^\s*$/ }

# read the next line and display it
say $fh.get;

close $fh;

 for only consumes from $fh.lines as needed

Copyright © 2012
http://www.pmichaud.com/2012/pres/