summaryrefslogtreecommitdiffhomepage
path: root/perl.html.markdown
diff options
context:
space:
mode:
authorDan Book <grinnz@gmail.com>2021-10-22 18:52:28 -0400
committerGitHub <noreply@github.com>2021-10-23 00:52:28 +0200
commitfa5048634d7e233341dd6ca27e78d02efe14b158 (patch)
treef2a5a1fa3db3cc261cac92bbeb4642302ad28585 /perl.html.markdown
parent9b6973886130e71aedb9fbad8366d45381d097f2 (diff)
[perl/en] Add example of iterating through file (#4238)
Diffstat (limited to 'perl.html.markdown')
-rw-r--r--perl.html.markdown6
1 files changed, 6 insertions, 0 deletions
diff --git a/perl.html.markdown b/perl.html.markdown
index 8811dd08..88185e9d 100644
--- a/perl.html.markdown
+++ b/perl.html.markdown
@@ -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.