Having the .match() and .replace() virtual methods is nice, but it
would be very convenient to have a 'destructive' substitute operator
which performs a regex substitution on a variable and returns true if
the substitution was performed and false otherwise.

For instance, a lot of validation+cleanup code can be written with
perl's s{}{} operator, e.g.:

# accept a number with possible leading and trailing whitespace:

if ($input =~ s{\A\s*(\d+)\s*\z}{$1}) {
  # input is a valid number and $input is the cleaned-up number
} else {
  # input is not valid
}

And it would be nice to be able to do this in TT. Is this already possible?

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

Reply via email to