Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm using a while loop to iterate over some text to find all the instances of a pattern match. When I do the substitution on the match, the process hangs (some how I've created an infinite loop?) I thought perhaps it was the "[]" characters in one of the variables that was causing problems on interpolation but escaping them didn't help. Is there a better way to substitute text on multiple matches when you need match specific substitutions?
while ($str =~ /<tag1[^>]*>\s*<tag2>\s*<tag3>([^<]*)<\/endtag3>/gsi) { ++$a; $b = $1; $b = $b . " [ $c-$a]"; $str =~ s/(<tag1[^>]*>\s*<tag2>\s*)<tag3>[^<]*<\/endtag3>/ +$1<tag3>$b<\/endtag3>/si; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: while loop w/match is hanging
by Eliya (Vicar) on Jan 13, 2012 at 19:55 UTC | |
|
Re: while loop w/match is hanging
by kennethk (Abbot) on Jan 13, 2012 at 20:05 UTC | |
|
Re: while loop w/match is hanging
by CountZero (Bishop) on Jan 13, 2012 at 19:51 UTC |