"perl-5.8.0@ton.iguana.be (via RT)" wrote: > > This code: > perl -wle ' > sub fun { > $a = shift; > print "fun(<$a>)"; > print "unexpectdly matched $& at position @-" if /^de/ > } > $_ = "ab\nde"; > s/^([\w\W]*)/fun("$1")/e' > > outputs (as expected): > fun(<ab > de>) > > However, this: > > perl -wle ' > sub fun { > $a = shift; > print "fun(<$a>)"; > print "unexpectdly matched $& at position @-" if /^de/ > } > $_ = "ab\nde"; > s/^([\w\W]*)/fun("$1")/em' > > outputs: > > fun(<ab > de>) > unexpectdly matched de at position 3 > > The only difference is the m modifier on the s/// > I didn't expect the "non-reentrant" regex problems here. Until now I > though the replacement part of a s/// was safe. > > Speculation: > It seems that m modifier propagates to the regex that's used in fun() which > gets called from the body. > Presumably one or more modifiers need localizing. Yes. Good catch. Setting /m on a match or on a substitution is equivalent to setting the global special variable $* to 1 (locally). Thus, it will influence the behaviour of all regexps that haven't /m or /s set in that scope. The interaction with $*, and the fact that $* can have remote effects, makes this bug difficult to solve. A first step would be to make $* lexically scoped (a compile-time hint, à la $[). Or to get rid of it.Thread Previous | Thread Next