summaryrefslogtreecommitdiff
path: root/pp_ctl.c
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-12-26 10:18:24 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-12-26 10:18:24 +0000
commit8e9bbdb923f8df09e5409a6d90b34d9a7bf447c4 (patch)
tree7dae4b3181d9dcabc28051c26c77578e31c7b4d0 /pp_ctl.c
parent3e9d3e5b21291ba6b38dda724868f34a49149045 (diff)
downloadperl-8e9bbdb923f8df09e5409a6d90b34d9a7bf447c4.tar.gz
Refactor the code that checks whether a range is numeric
or string-magical. p4raw-id: //depot/perl@21960
Diffstat (limited to 'pp_ctl.c')
-rw-r--r--pp_ctl.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index 045edd4270..ab4ab84c3c 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1031,6 +1031,16 @@ PP(pp_flip)
}
}
+/* This code tries to decide if "$left .. $right" should use the
+ magical string increment, or if the range is numeric (we make
+ an exception for .."0" [#18165]). AMS 20021031. */
+
+#define RANGE_IS_NUMERIC(left,right) ( \
+ SvNIOKp(left) || !SvPOKp(left) || \
+ SvNIOKp(right) || !SvPOKp(right) || \
+ (looks_like_number(left) && *SvPVX(left) != '0' && \
+ looks_like_number(right)))
+
PP(pp_flop)
{
dSP;
@@ -1046,15 +1056,7 @@ PP(pp_flop)
if (SvGMAGICAL(right))
mg_get(right);
- /* This code tries to decide if "$left .. $right" should use the
- magical string increment, or if the range is numeric (we make
- an exception for .."0" [#18165]). AMS 20021031. */
-
- if (SvNIOKp(left) || !SvPOKp(left) ||
- SvNIOKp(right) || !SvPOKp(right) ||
- (looks_like_number(left) && *SvPVX(left) != '0' &&
- looks_like_number(right)))
- {
+ if (RANGE_IS_NUMERIC(left,right)) {
if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX)
DIE(aTHX_ "Range iterator outside integer range");
i = SvIV(left);
@@ -1769,12 +1771,7 @@ PP(pp_enteriter)
cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) {
dPOPss;
- /* See comment in pp_flop() */
- if (SvNIOKp(sv) || !SvPOKp(sv) ||
- 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)))
- {
+ if (RANGE_IS_NUMERIC(sv,(SV*)cx->blk_loop.iterary)) {
if (SvNV(sv) < IV_MIN ||
SvNV((SV*)cx->blk_loop.iterary) >= IV_MAX)
DIE(aTHX_ "Range iterator outside integer range");