You can create a file with one term, phrase of RE per line then just read it into an array and chomp it. You generate a precompiled RE as shown. Then just iterate over the infile lines*. Then just print the modified data out to STDOUT or a file.
* I say lines but you may note the $/ = "\n\n". The $/ is the input record separator (normally \n). By setting it to two newlines we read in whole paragraphs at a time and thus can make matches across line breaks.
The RE needs \b boundary conditions to make it match full words. If you want extra chars I suggest \w* for extra word chars and \W+ to represent punctuation or whitespace between words whan looking for phrases.
my @highlights = ( 'foo', 'bar', 'baz', '\w*a\W+my\w*', # the ...a my... phrase example ); my $re = join '|', @highlights; $re = qr/\b($re)\b/i; local $/ = "\n\n"; # read in a para at a time while(<DATA>){ s/$re/uc $1/ge; print; } __DATA__ Hello Foo, This is your friend Baz wondering if you would like to go to the bar to talk server foo. Barclays is a foobar bank BTW. So a Perlmonk and a Panda walk into a bar. Know I know you think this is going to be a joke but I saw the panda myself!
cheers
tachyon
In reply to Re: Text markup confusion
by tachyon
in thread Text markup confusion
by paurus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |