$template =~ s[ \[% \s+ IF \s+ (\w+) \s+ %\] # $1 var (.*?) # $2 then \[% \s+ END \s+ %\] ][do { my($a, $b, $c) = ($1, $2, ''); if ($b =~ /[% \s+ ELSE \s+ %]/gsx) { #==============^ ^ backslashes removed! my(@c) = split(/[%\s+ELSE\s+%]/s, $b, 2); #=======================^ ^ backslashes removed! warn 'c(', join('|', @c), ')' if DEBUG; $b = $c[0]; $c = $c[1]; } warn "a($a) b($b) c($c)\n----\n" if DEBUG; defined $$v{$a} && $$v{$a} ? $b : $c; };]egsx;
Note that the backslashes were removed from the regexes! Time for a bug report?
On a hunch, I changed the second set of delimeters from square brackets to curly brackets, the output is as you expected originally.
Update: perl 5.8.0 (ActiveState build 806) on Win2K
Update: The more I think about it, I don't consider this a bug. If you use double-quotes to delimit a string ("\"Hello\""), backwhacking the delimiter results in the double quote as part of the string. The same should hold for square brackets as a delimiter.
In reply to Re: matching / splitting within a substitution
by jsprat
in thread matching / splitting within a substitution
by PodMaster
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |