From: Willem on
Ben Morrow wrote:
) It shouldn't need to be complicated.
)
) while ($content =~ /foo(\d+)/g) {
) my ($start, $end) = ($-[0], $+[0]);
) # this qq// should contain exactly what you would have put
) # in the RHS of the s///
) my $after = qq/bar$1/;
) my $before = substr $content, $start, $end, $after;
) }

I did something similar. However, because I didn't want to duplicate this
code 5 times, I put it into a function, and that meant hand-parsing for $1,
$2, etc. variables. Which made it quite complicated.

However, the s///e solution mentioned crossthread had good potential:

$content =~ s/<complicated expression (with parens)>/
func("<Another expression with $1 and stuff>")/ge;

sub func { print "Sub '$&' by '$_[0]'"; $_[0]; }

Which works like a charm.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
From: Willem on
sln(a)netherlands.com wrote:
) $content =~ s/(<add key=".*?\.foobar\.)(\d+)(" value="Foo=)(.*?)(;.*?"\/>)/
) $tmp = $1.'10'.$3.'20'.$5;
) print "Substitution: '$1$2$3$4$5'\n => '$tmp'\n";
) $tmp/eg;

Yep, thanks, that worked quite well. (I put the expression into
a function, and used $& instead of $1$2$3$4$5, though.)


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT