mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
[perl/en] Add example of iterating through file (#4238)
This commit is contained in:
parent
9b69738861
commit
fa5048634d
@ -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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user