From fa5048634d7e233341dd6ca27e78d02efe14b158 Mon Sep 17 00:00:00 2001 From: Dan Book Date: Fri, 22 Oct 2021 18:52:28 -0400 Subject: [perl/en] Add example of iterating through file (#4238) --- perl.html.markdown | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'perl.html.markdown') 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. -- cgit v1.2.3