> > - stash replace back references
> >
> > http://www.template-toolkit.org/pipermail/templates/2001-April/000905.h
> tml
> >
> > Again, probably not for the current release but these comments could
> > be added to the TODO under this item:
> >
> > * Richard Tietjen's patch for stash replace. Allows back
> > references (e.g. $1) but it would be nice to find a
> > rock-solid way to implement it without relying on
> > unusual ^A delimiter character.
>
> Yep, added it. Any ideas about how to fix the underlying problem or am
> I worrying about nothing?
It would be great if replace handled backreferences. I don't like the
^A solution since the string could contain ^A, plus it is a security hole.
The attempt I posted only works for up to 9 backreferences and doesn't
handle an escaped '\$' and uses nested evals:
$str =~ s{$search}{
my $r = $replace;
my @d = (0, $1, $2, $3, $4, $5, $6, $7, $8, $9);
$r =~ s/\$(\d+)/$d[$1]/eg;
$r;
}eg;
I wish there was a perl predefined variable array containing all the
backreferences (is there one?). You can avoid the hard-coded limit
of 9 with extra evals, and a bit of work on the re could handle the
escaped '\$' case, so maybe that would be good enough.
Craig