in reply to Re^2: Printing th entire line with a keyword
in thread Printing th entire line with a keyword
It's even easier with grep. But in perl, grep wants to match against a list, so you'll be back to reading line-by-line:
#!/usr/bin/perl use strict; use warnings print "<$_>\n" for grep {chomp; /(fox|wood)/} <DATA>; __DATA__ Now is the time for all good men to come to the aid of their party. The quick red fox jumped over the lazy brown dog. How much wood can a woodchuck chuck? If a woodchuck could chuck wood?
This should give the same result. (Note: the chomp isn't required, but I wanted to match the output of the previous code, so I put it in.)
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Printing th entire line with a keyword
by Anonymous Monk on Dec 31, 2012 at 05:58 UTC |