Thanks -- this was brief and clear enough that you should have put that into the OP, instead of making up a "pseudo/generic" case to confuse us. :)
Anyway, I would tend to prefer taking a two-step approach: apply all the substitutions that work, and after those are all done, if any residual template-variable markers are left behind, then croak. Something like this:
"Basic" regex substitutions tend to be obscure and cryptic enough by themselves, without adding flow-control logic into the rhs. The code will be easier to maintain if you segregate the regex operations from the flow-control.my %hash = ( var1 => 'value1', var2 => 'value2' ); # ... or whatever... while ( $tmpl =~ /@~(.*?)~@/ and exists( $hash{$1} )) { my $var = $1; $tmpl =~ s/@~$var~@/$hash{$var}/g; } croak "Bad template text:\n$tmpl" if ( $tmpl =~ /@~|~@/ );
In reply to Re^5: die in regexp
by graff
in thread die in regexp
by powerman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |