This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #19078] wrong match order inside replacement
authorFather Chrysostomos <sprout@cpan.org>
Tue, 21 Sep 2010 04:24:02 +0000 (21:24 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 21 Sep 2010 04:24:02 +0000 (21:24 -0700)
commitaf9838cc2fa3350e15e88a27008899ae3a3afdb6
tree8312e06f5b3a831c414acd68fe51ce7c029c4c44
parentebcfa0534aa7072c0353af79a1e3d7e87678e73e
[perl #19078] wrong match order inside replacement

$ perl -le '$_="CCCGGG"; s!.!@a{print("[$&]"),/./}!g'
[C]
[C]
[C]
[C]
[C]
[C]

What’s happening is that the s/// does not reset PL_curpm for each
iteration, because it doesn’t usually have to.

The RHS’s scoping takes care of it most of the time. This happens with
the /e modifier and with @{...}.

In this example, though, we have a subscript, not a block. This sub-
script is in the same scope as the s/// itself.

The assumption that the substitution operator will never have to reset
PL_curpm itself appears to be incorrect. This fixes it.
pp_ctl.c
t/re/subst.t