Perl 5 lists are eager
Naive (i.e., incorrect) Perl 5 program to print the line following the first blank line in a file:
# P5 code! # open file.txt open my $fh, '<', 'file.txt' or die; # read from file.txt until we find a blank line foreach (<$fh>) { last if /^\s*$/ } # read the next line and print it my $line = <$fh>; print $line; close $fh;
✗ foreach (<$fh>) consumes all of the lines