Andy Wardley wrote:
> I'll give it some more thought.  I'll also dig through the archives and
> see what other proposals we've had to solve this.  Any of those people 
> who have made suggestions are welcome to chip in again here, to refresh
> our memories if nothing else.

This is the most promising candidate from Craig Barratt. 

sub replace { 
    my ($str, $search, $replace) = @_;
    $replace = '' unless defined $replace;
    return $str unless defined $str and defined $search;

    $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;
    }egx;

    return $str;
}

It's limited to the first 9 captures only (no $10, $11, etc) and it 
doesn't handle escaped '\$' in the replacement string.  But apart from
that, it seems to do the job without opening up any security holes.

A


_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to