in reply to newbie questions on array access and control loops
So if the current line being read has a successful match of the regex, add it to the array of matched lines. After you have read thru the entire file, print each line that matched.#!/apps/bin/perl -w use strict; my @lines_that_matched = (); while (<>) { chomp; if (/PAGE: 2/) { push (@lines_that_matched, $_); } } foreach my $line (@lines_that_matched) { print "$line\n"; }
|
|---|