Perl_croak(aTHX_ "Can't use %s for loop variable", PL_op_desc[sv->op_type]);
}
else {
- sv = newGVOP(OP_GV, 0, PL_defgv);
+ I32 offset = pad_findmy("$_");
+ if (offset == NOT_IN_PAD || PAD_COMPNAME_FLAGS(offset) & SVpad_OUR) {
+ sv = newGVOP(OP_GV, 0, PL_defgv);
+ }
+ else {
+ padoff = offset;
+ iterpflags = OPpLVAL_INTRO; /* my $_; for () */
+ }
}
if (expr->op_type == OP_RV2AV || expr->op_type == OP_PADAV) {
expr = mod(force_list(scalar(ref(expr, OP_ITER))), OP_GREPSTART);
@INC = '../lib';
}
-print "1..56\n";
+print "1..64\n";
my $test = 0;
sub ok ($$) {
ok( our $_ eq 'global', '...our $_ restored outside for my $_' );
}
{
+ my $_ = 'local';
+ for ("implicit foo") { # implicit "my $_"
+ ok( $_ eq "implicit foo", 'for implicit my $_' );
+ /(.)/;
+ ok( $1 eq "i", '...m// in for implicity my $_' );
+ ok( our $_ eq 'global', '...our $_ inside for implicit my $_' );
+ }
+ ok( $_ eq 'local', '...my $_ restored outside for implicit my $_' );
+ ok( our $_ eq 'global', '...our $_ restored outside for implicit my $_' );
+}
+{
+ my $_ = 'local';
+ ok( $_ eq "postfix foo", 'postfix for' ) for 'postfix foo';
+ ok( $_ eq 'local', '...my $_ restored outside postfix for' );
+ ok( our $_ eq 'global', '...our $_ restored outside postfix for' );
+}
+{
for our $_ ("bar") {
ok( $_ eq "bar", 'for our $_' );
/(.)/;