
Repeat string matching/substituting ?
I am relatively new to Perl, and I am trying to do what seems to be a
fairly simple operation, without much success.
I need to surround each occurrence of a string within a line with
begin and end tags, i.e. "the place the fox went is the chickencoop"
with keyword "the" needs to become "<begin>the<end> place
<begin>the<end> fox went is <begin>the<end> chickencoop".
Here's what I tried:
#!/usr/bin/perl -p
while (/the/g) {
$_ = $` . "<begin>" . $& . "<end>" . $';
Quote:
}
but this fails unpredictably, probably because //g doesn't like the
fact that $_ is changing on it. Any insight into how //g works
internally, or a better way to accomplish this in general would be
much appreciated. Thanks!
-ts-
--
Oracle Corporation, Box 659412, Redwood Shores, CA, 94065 =What .sig virus?=