diff options
-rw-r--r-- | pp_ctl.c | 1 | ||||
-rw-r--r-- | t/re/subst.t | 24 |
2 files changed, 24 insertions, 1 deletions
@@ -377,6 +377,7 @@ PP(pp_substcont) (void)ReREFCNT_inc(rx); cx->sb_rxtainted |= RX_MATCH_TAINTED(rx); rxres_save(&cx->sb_rxres, rx); + PL_curpm = pm; RETURNOP(pm->op_pmstashstartu.op_pmreplstart); } diff --git a/t/re/subst.t b/t/re/subst.t index 91c757a8a5..9b5fd61c63 100644 --- a/t/re/subst.t +++ b/t/re/subst.t @@ -7,7 +7,7 @@ BEGIN { } require './test.pl'; -plan( tests => 170 ); +plan( tests => 172 ); # Stolen from re/ReTest.pl. Can't just use the file since it doesn't support # like() and it conflicts with test.pl @@ -724,3 +724,25 @@ fresh_perl_is( '$_="abcef"; s/bc|(.)\G(.)/$1 ? "[$1-$2]" : "XX"/ge; print' => 'a $string =~ s/./\777/; is($string, chr 0x1FF, "Verify that handles s/foo/\\777/"); } + +# Scoping of s//the RHS/ when there is no /e +# Tests based on [perl #19078] +{ + local *_; + my $output = ''; my %a; + no warnings 'uninitialized'; + + $_="CCCGGG"; + s!.!<@a{$output .= ("$&"),/[$&]/g}>!g; + $output .= $_; + is( + $output, "CCCGGG< >< >< >< >< >< >", + 's/// sets PL_curpm for each iteration even when the RHS has set it' + ); + + s/C/$a{m\G\}/; + is( + "$&", G => + 'Match vars reflect the last match after s/pat/$a{m|pat|}/ without /e' + ); +} |