New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"0" fails as right-hand argument to .. #6047
Comments
From @mjdominusCreated by @mjdominusperl -e 'print "-4" .. "0"' This prints nothing. The problem persists in 5.7.3. Perl Info
|
From ams@wiw.orgAt 2002-10-30 17:27:53 -0000, perlbug@perl.org wrote:
This is a very old bug, introduced by: | Change 4730 by gsar@auger on 1999/12/28 19:55:56 (Ha ha, Andreas. :-) The appended patch fixes it. -- ams Change 18073 by ams@lustre on 2002/10/30 19:47:12 Subject: [perl #18165] "0" fails as right-hand argument to .. Affected files ... ...... //depot/perl/pp_ctl.c#325 edit Differences ... ==== //depot/perl/pp_ctl.c#325 (text) ==== Inline Patch--- perl/pp_ctl.c#324~18048~ Tue Oct 22 22:34:26 2002
+++ perl/pp_ctl.c Thu Oct 31 01:17:12 2002
@@ -943,10 +943,15 @@
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) && *SvPVX(right) != '0'))
+ looks_like_number(right) && (*SvPVX(right) != '0' ||
+ SvCUR(right) == 1)))
{
if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX)
DIE(aTHX_ "Range iterator outside integer range");
Inline Patch--- perl/t/op/range.t#8~4730~ Wed Dec 29 01:25:56 1999
+++ perl/t/op/range.t Thu Oct 31 01:17:12 2002
@@ -1,6 +1,6 @@
#!./perl
-print "1..15\n";
+print "1..16\n";
print join(':',1..5) eq '1:2:3:4:5' ? "ok 1\n" : "not ok 1\n";
@@ -73,3 +73,7 @@
print "not ";
}
print "ok 15\n";
+
+# [#18165] Should allow "-4".."0", broken by #4730. (AMS 20021031)
+print "not " unless 5 == (() = "-4".."0");
+print "ok 16\n"; |
From @eserteAbhijit Menon-Sen <ams@wiw.org> writes:
Please see also [perl #18114] and the patch there, which also handles Regards,
-- tknotes - A knotes clone, written in Perl/Tk. |
From ams@wiw.orgAt 2002-10-31 00:13:51 +0100, slaven.rezic@berlin.de wrote:
Thanks, I've applied that patch with Yves Orton's tests and my comments, -- ams, clearly not reading p5p with both eyes. |
From @eserteAbhijit Menon-Sen <ams@wiw.org> writes:
Here's a similar patch for the for ("-4" .. "0") { ... } case: Inline Patch--- bleedperl/pp_ctl.c Mon Nov 25 04:42:18 2002
+++ bleedperl3/pp_ctl.c Fri Nov 29 23:50:32 2002
@@ -1690,11 +1690,11 @@ 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) &&
- *SvPVX(cx->blk_loop.iterary) != '0'))
+ looks_like_number((SV*)cx->blk_loop.iterary)))
{
if (SvNV(sv) < IV_MIN ||
SvNV((SV*)cx->blk_loop.iterary) >= IV_MAX)
--- bleedperl/t/cmd/for.t Thu May 10 15:28:03 2001
+++ bleedperl3/t/cmd/for.t Fri Nov 29 23:43:39 2002
@@ -1,6 +1,6 @@
#!./perl
-print "1..11\n";
+print "1..12\n";
for ($i = 0; $i <= 10; $i++) {
$x[$i] = $i;
@@ -66,3 +66,8 @@ foreach $b (bar()) {
}
print $a == 7 ? "ok" : "not ok", " 11\n";
+$loop_count = 0;
+for ("-3" .. "0") {
+ $loop_count++;
+}
+print $loop_count == 4 ? "ok" : "not ok", " 12\n";
-- Slaven Rezic - slaven.rezic@berlin.de Tk-AppMaster: a perl/Tk module launcher designed for handhelds |
From @rgsSlaven Rezic wrote:
Thanks, applied as #18264. |
@rgs - Status changed from 'new' to 'resolved' |
Migrated from rt.perl.org#18165 (status was 'resolved')
Searchable as RT18165$
The text was updated successfully, but these errors were encountered: