Re: Search for a Word in a file

2006-06-07 Thread John W. Krahn
anu p wrote: > Hi All, Hello, > I have a requirement where I need to check if a word > exists in a text file and if so, get the whole line of > text which contains the word. I also need to split the > line on space. > > Example: > >1 1 0 0 P 6/6 > - > Code: > >

Re: Search for a Word in a file

2006-06-07 Thread Adriano Ferreira
It seems like I did not read enough of your message to give you a sensible answer to your problem. # write a function to do what the one-liner did, but stopping at the first row sub find_first { my $regex = shift; local @ARGV = @_; while (<>) { retu

Re: Search for a Word in a file

2006-06-07 Thread Adriano Ferreira
This one-liner works a bit like a (Unix) grep: perl -n -e 'print if //' temp.txt and is probably efficient enough for most cases. On 6/7/06, anu p <[EMAIL PROTECTED]> wrote: Hi All, I have a requirement where I need to check if a word exists in a text file and if so, get the whole line of t