in reply to matching / splitting within a substitution
A quick trip through Deparse shows that perl changes the substitution to this:
$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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: matching / splitting within a substitution
by PodMaster (Abbot) on Jul 15, 2003 at 01:38 UTC | |
by tye (Sage) on Jul 15, 2003 at 16:56 UTC | |
by PodMaster (Abbot) on Jul 16, 2003 at 07:16 UTC |
In Section
Seekers of Perl Wisdom