[perl/en] Add example of iterating through file (#4238)

This commit is contained in:
Dan Book 2021-10-22 18:52:28 -04:00 committed by GitHub
parent 9b69738861
commit fa5048634d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -217,6 +217,12 @@ open(my $log, ">>", "my.log") or die "Can't open my.log: $!";
my $line = <$in>;
my @lines = <$in>;
# You can iterate through the lines in a file one at a time with a while loop:
while (my $line = <$in>) {
print "Found apples\n" if $line =~ m/apples/;
}
# You can write to an open filehandle using the standard "print"
# function.