in reply to Functions in substitutions (s///) and Perl 5.8.

Rewriting it to use pos() like this works for me:
while (m/\[\[\w+\]\]/) { my $oldpos = pos; m/\[\[(\w+)\]\]/; my $expansion = $helper->($1); pos = $oldpos; s/[[$1]]/$expansion/; }
It's a little nasty due to matching more times than I'd like, but it works. :)

Replies are listed 'Best First'.
Re: Re: Functions in substitutions (s///) and Perl 5.8.
by teichman (Novice) on Oct 24, 2002 at 16:44 UTC
    Grr, that'll teach me to make changes without testing. The substitution needs to have those square brackets escaped:
    while (m/\[\[\w+\]\]/) { my $oldpos = pos; m/\[\[(\w+)\]\]/; my $expansion = $helper->($1); pos = $oldpos; s/\[\[$1\]\]/$expansion/; }