diff --git a/pp_ctl.c b/pp_ctl.c index 7b059dee6e..380caf1b37 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -4132,8 +4132,10 @@ PP(pp_entereval) if (PL_op->op_private & OPpEVAL_HAS_HH) { saved_hh = MUTABLE_HV(SvREFCNT_inc(POPs)); } - else if (PL_op->op_private & OPpEVAL_COPHH - && PL_curcop->cop_hints & HINT_LOCALIZE_HH) { + else if (PL_hints & HINT_LOCALIZE_HH || ( + PL_op->op_private & OPpEVAL_COPHH + && PL_curcop->cop_hints & HINT_LOCALIZE_HH + )) { saved_hh = cop_hints_2hv(PL_curcop, 0); hv_magic(saved_hh, NULL, PERL_MAGIC_hints); } diff --git a/t/op/eval.t b/t/op/eval.t index 49a1ccab41..75da7eceb3 100644 --- a/t/op/eval.t +++ b/t/op/eval.t @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan(tests => 118); +plan(tests => 119); eval 'pass();'; @@ -567,3 +567,15 @@ for my $k (!0) { is "a" =~ /a/, "1", "string eval leaves readonly lexicals readonly [perl #19135]"; } + +fresh_perl_is(<<'EOP', "ok\nok\nok\n", undef, 'eval clears %^H'); + BEGIN { + require re; re->import('/x'); # should only affect surrounding scope + eval ' + print "a b" =~ /a b/ ? "ok\n" : "nokay\n"; + use re "/m"; + print "a b" =~ /a b/ ? "ok\n" : "nokay\n"; + '; + } + print "ab" =~ /a b/ ? "ok\n" : "nokay\n"; +EOP