1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-08-01 04:20:39 +02:00

[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

View File

@@ -217,6 +217,12 @@ open(my $log, ">>", "my.log") or die "Can't open my.log: $!";
my $line = <$in>; my $line = <$in>;
my @lines = <$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" # You can write to an open filehandle using the standard "print"
# function. # function.