Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi , I have an input file with multiple lines.The code is to search for a particular word in the line and to print the entire line if the word is present.Currently i am using a code as shown below
use strict; my $find = "word or string to find"; open FILE, "<searchfile.txt"; my @line = <FILE>; print "Lined that matched $find\n"; for (@lines) { if ($_ =~ /$find/) { print "$_\n"; } }
But here we are iterating through each line which is time consuming.Is there an easy method?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Printing th entire line with a keyword
by roboticus (Chancellor) on Dec 31, 2012 at 05:11 UTC | |
by Anonymous Monk on Dec 31, 2012 at 05:23 UTC | |
by roboticus (Chancellor) on Dec 31, 2012 at 05:40 UTC | |
by Anonymous Monk on Dec 31, 2012 at 05:58 UTC | |
|
Re: Printing th entire line with a keyword
by RichardK (Parson) on Dec 31, 2012 at 11:25 UTC | |
|
Re: Printing th entire line with a keyword
by Anonymous Monk on Dec 31, 2012 at 13:13 UTC | |
|
Re: Printing th entire line with a keyword
by Anonymous Monk on Dec 31, 2012 at 04:57 UTC |