[Templates] regex
Mark Mills
mark@xodiax.com
Fri, 8 Mar 2002 09:10:29 -0500
> Is someone bringing the m// operator to TT2 ? How about=20
> .replace() with
> access to the $numbers ? Would be useful.
Unfortunately, the right side of replace is deliberately quoted for =
security. You shouldn't be able to call arbitrary perl code from the =
templates. And parsing out just the $1 style variables isn't the obvious =
case it first appears.
[% a.replace('.*','@{[`rm -rf`]}') %]
Of course, if you aren't afraid of that (and you promise to never send =
the replace side directly from date that a site user could load and you =
dont mind potentially fatal errors) then you can do this after calling =
'use Template;':
Template::Stash::STASH_OPS->{replacex} =3D> sub {
my ($str, $search, $replace) =3D @_;
$replace =3D '' unless defined $replace;
return $str unless defined $str and defined $search;
eval "\$str =3D~ s^A$search^A$replace^Ag";
return $str;
};
But seriously, you'll probably be sorry eventually...
--mark