develooper Front page | perl.perl5.porters | Postings from June 2003

Re: [perl #22354] s/// flags influence regex use in the replacement body

Thread Previous | Thread Next
June 4, 2003 05:07
Re: [perl #22354] s/// flags influence regex use in the replacement body
Message ID:
In article <20030603155453.4004_58e.rgarciasuarez@_ree._r>,
	Rafael Garcia-Suarez <> writes:
> 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.

That makes things even weirder:

perl -wle '
sub fun {
    $a = shift;
    print "\$* is undef" if !defined($*);
    local $* = undef;
    print "fun(<$a>)";
    print "unexpectdly matched $& at position @-" if /^de/
$_ = "ab\nde";


Use of $* is deprecated at -e line 4.
$* is undef
Use of uninitialized value in scalar assignment at -e line 5.

So setting $* to undef (or 0) indeed solves it.
However, the test before the local shows that $* actually
already was undef !. But removing the local makes it fail again.
Urgh !

> 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.

Making $* lexically scoped probably already breaks pograms that still
depend on it. So kill it, I'd say. It has been documented as deprecated
for a long time, and gives a deprecation warning in actual code.
Now it's also clear it causes bugs in real code.
(nope, this wasn't a golf thing :-) )
seen in rec.arts.sf.written: "Perl Harbor" was the C-port for Awk-land, NZ

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About