in reply to Re: printing the line after grepping
in thread printing the line after grepping
A beginner's version of that would be:
use strict; use warnings; use 5.010; my $pattern = '0 Items in Feed & 0 New Fetched items'; open(my $INFILE, "<", "data2.txt") or die "There was a problem: $!"; while (my $line = <$INFILE>) { print $line if $line =~ /$pattern/; }
If you write the while loop like this:
while (<$INFILE>) { }
it becomes magical in perl. Every time through the while loop, the next line from the file will be read into a variable named $_. Calling print with no arguments will print $_, and a regex will match against $_ by default.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: printing the line after grepping
by ikegami (Patriarch) on Nov 11, 2009 at 17:50 UTC | |
by 7stud (Deacon) on Nov 11, 2009 at 18:23 UTC | |
by ikegami (Patriarch) on Nov 11, 2009 at 18:29 UTC |