diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 1999-12-28 19:55:56 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1999-12-28 19:55:56 +0000 |
commit | 24d49c17ff0f21aad54a06ae1065494e6e626556 (patch) | |
tree | a35d37a29b5dd3ed938a5943dad60389ef1f0c13 | |
parent | 79c1c09ad7d8b945e744760f535fd8e00a030ec5 (diff) | |
download | perl-24d49c17ff0f21aad54a06ae1065494e6e626556.tar.gz |
range operator does magical string increment iff both operands
are non-numbers, from Tom Phoenix <rootbeer@redcat.com>; fixed
the "foreach (RANGE)" case as well
p4raw-id: //depot/perl@4730
-rw-r--r-- | pp_ctl.c | 10 | ||||
-rwxr-xr-x | t/op/range.t | 11 |
2 files changed, 18 insertions, 3 deletions
@@ -997,7 +997,9 @@ PP(pp_flop) mg_get(right); if (SvNIOKp(left) || !SvPOKp(left) || - (looks_like_number(left) && *SvPVX(left) != '0') ) + SvNIOKp(right) || !SvPOKp(right) || + (looks_like_number(left) && *SvPVX(left) != '0' && + looks_like_number(right) && *SvPVX(right) != '0')) { if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX) DIE(aTHX_ "Range iterator outside integer range"); @@ -1674,7 +1676,11 @@ PP(pp_enteriter) if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) { dPOPss; if (SvNIOKp(sv) || !SvPOKp(sv) || - (looks_like_number(sv) && *SvPVX(sv) != '0')) { + SvNIOKp(cx->blk_loop.iterary) || !SvPOKp(cx->blk_loop.iterary) || + (looks_like_number(sv) && *SvPVX(sv) != '0' && + looks_like_number((SV*)cx->blk_loop.iterary) && + *SvPVX(cx->blk_loop.iterary) != '0')) + { if (SvNV(sv) < IV_MIN || SvNV((SV*)cx->blk_loop.iterary) >= IV_MAX) DIE(aTHX_ "Range iterator outside integer range"); diff --git a/t/op/range.t b/t/op/range.t index 1698db4a55..e8aecf5fc9 100755 --- a/t/op/range.t +++ b/t/op/range.t @@ -1,6 +1,6 @@ #!./perl -print "1..13\n"; +print "1..15\n"; print join(':',1..5) eq '1:2:3:4:5' ? "ok 1\n" : "not ok 1\n"; @@ -64,3 +64,12 @@ print "ok 12\n"; $bad = 1 unless $x eq 'a:b:c:d:e'; print $bad ? "not ok 13\n" : "ok 13\n"; } + +# Should use magical autoinc only when both are strings +print "not " unless 0 == (() = "0"..-1); +print "ok 14\n"; + +for my $x ("0"..-1) { + print "not "; +} +print "ok 15\n"; |