in reply to how can i search a text file for a string and print every occurence of that string
my @list = grep /\btest\b/, <DATA>; chomp @list; print "$_\n" foreach @list; __DATA__ This is only a test. Here's a line that doesn't contain the trigger text. This line contains test and test again. Now you see it, now you don't. Testing one two three. Test or not to test?
This passes a filehandle to grep, along with a simple regexp that tells it to find only those lines that contain the word "test" (rejecting words like 'testing').
For matches across multiple lines you have to set the $/ special variable to paragraph or slurp mode and use an /s modifier on your regexp.
|
|---|