From 459b64da6c5743fa9093a9ef5214a82b46f2f7d0 Mon Sep 17 00:00:00 2001 From: Hojung Yoon Date: Tue, 24 May 2011 18:18:14 -0700 Subject: [perl #90888] each(ARRAY) on scalar context should wrapped into defined() "perldoc -f each" says that if each() is performed on ARRAY in scalar context, it will return only the index in an array. Calling each(HASH) in scalar context worked well but calling each(ARRAY) didn't because it was not wrapped into defined OPCODE. So, in Perl_newWHILEOP() and Perl_newLOOPOP(), they are modified to check them and wrap with defined OP if needed. In S_new_logop(), it's reasonable to warn if return value of each(ARRAY) is being used for boolean value, as it's first return value will be "0", the false. issue: #90888 link: http://rt.perl.org/rt3/Public/Bug/Display.html?id=90888 --- op.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'op.c') diff --git a/op.c b/op.c index 0d4e1e6ad6..e1bf3539c5 100644 --- a/op.c +++ b/op.c @@ -5103,7 +5103,8 @@ S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp) if (k1->op_type == OP_READDIR || k1->op_type == OP_GLOB || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB) - || k1->op_type == OP_EACH) + || k1->op_type == OP_EACH + || k1->op_type == OP_AEACH) { warnop = ((k1->op_type == OP_NULL) ? (OPCODE)k1->op_targ : k1->op_type); @@ -5347,7 +5348,8 @@ Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block) if (k1 && (k1->op_type == OP_READDIR || k1->op_type == OP_GLOB || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB) - || k1->op_type == OP_EACH)) + || k1->op_type == OP_EACH + || k1->op_type == OP_AEACH)) expr = newUNOP(OP_DEFINED, 0, expr); break; } @@ -5435,7 +5437,8 @@ Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop, if (k1 && (k1->op_type == OP_READDIR || k1->op_type == OP_GLOB || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB) - || k1->op_type == OP_EACH)) + || k1->op_type == OP_EACH + || k1->op_type == OP_AEACH)) expr = newUNOP(OP_DEFINED, 0, expr); break; } -- cgit v1.2.1