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
"-4".."0" range not working #6040
Comments
From a.shankar@ti.comCreated by a.shankar@ti.comThis is a bug report for perl from a.shankar@ti.com, ----------------------------------------------------------------- $w1=<STDIN>; [run] it prints nothing! Perl Info
|
From @tamiasOn Mon, Oct 28, 2002 at 08:18:24AM -0000, a.shankar@ti.com (via RT) wrote:
I see that you are running Perl on Windows. Try printing a blank line $w1=<STDIN>; Some Windows shells seem to hide the first line of output. Ronald |
From a.shankar@ti.comHi Ronald The print("\n"); is not solving the problem. In fact a new problem has come Abhishek Shankar -----Original Message----- On Mon, Oct 28, 2002 at 08:18:24AM -0000, a.shankar@ti.com (via RT) wrote:
I see that you are running Perl on Windows. Try printing a blank line $w1=<STDIN>; Some Windows shells seem to hide the first line of output. Ronald |
From @tamiasOn Tue, Oct 29, 2002 at 08:58:49AM +0530, Abhishek Shankar wrote:
I have confirmed this behavior under perl5.6.1 and perl5.8.0, with help However, under perl5.6.1 and perl5.8.0, the range operator returns an empty The behavior seems to occur whenever both operands are strings: perl/bin/perl -wle 'print "-4\n".."0\n"' If either operand is a number, a list is returned. perl -wle 'print "-4"..0' Is this a bug, or an intended change in behavior? Abhishek, you can get the behavior you want by explicitly converting an perl -wle '$w1="-4"; $w2="0"; print 0+$w1..$w2' Ronald |
From @demerphq
Im pretty sure that this is not the cause of the problem. To which Abhishek Shankar said on 29 October 2002 04:34
I agree that this is a bug. It appears to be because the strings '0\n' and At first I thought this was due to the documented behaviour of the .. E:\Bin>perl -e "print qq{-4\n}..qq{-0\n}" Which is more or less DWIM i think. But this sure isnt: E:\Bin>perl -e "print qq{-4\n}..qq{0\n}" E:\Bin> So, my vote is that this is a bug. (it works with ("-4\n".."-0\n") but not V:\perl\lib\CPAN>perl -e "print qq{-4}..qq{0}" V:\perl\lib\CPAN>perl -e "print 0+qq{-4}..0+qq{0}" Luckily the workaround is trivial indeed. Simply coerce numeric context. @numlist = (0+$w1 .. 0+$w2); or $w1=0+<STDIN>; HTH. Yves Summary of my perl5 (revision 5 version 6 subversion 1) configuration: Characteristics of this binary (from libperl): |
From @demerphq
I just checked and under the lastest patch of bleadperl there is the same Inline Patch--- source\t\op\range.t Tue Aug 1 04:32:14 2000
+++ mysource\t\op\range.t Wed Oct 30 12:51:38 2002
@@ -1,6 +1,6 @@
#!./perl
-print "1..15\n";
+print "1..19\n";
print join(':',1..5) eq '1:2:3:4:5' ? "ok 1\n" : "not ok 1\n";
@@ -73,3 +73,9 @@
print "not ";
}
print "ok 15\n";
+
+# These should produce the same results or we don't DWIM
+print join(":","-4".."0") eq "-4:-3:-2:-1:0" ? "ok 16\n" : "not ok
|
From @demerphqrange.patch--- source\t\op\range.t Tue Aug 1 04:32:14 2000
+++ mysource\t\op\range.t Wed Oct 30 12:51:38 2002
@@ -1,6 +1,6 @@
#!./perl
-print "1..15\n";
+print "1..19\n";
print join(':',1..5) eq '1:2:3:4:5' ? "ok 1\n" : "not ok 1\n";
@@ -73,3 +73,9 @@
print "not ";
}
print "ok 15\n";
+
+# These should produce the same results or we don't DWIM
+print join(":","-4".."0") eq "-4:-3:-2:-1:0" ? "ok 16\n" : "not ok 16\n";
+print join(":","-4".."-0") eq "-4:-3:-2:-1:0" ? "ok 17\n" : "not ok 17\n";
+print join(":","-4\n".."0\n") eq "-4:-3:-2:-1:0" ? "ok 18\n" : "not ok 18\n";
+print join(":","-4\n".."-0\n") eq "-4:-3:-2:-1:0" ? "ok 19\n" : "not ok 19\n";
|
From @eserte"Orton, Yves" <yves.orton@mciworldcom.de> writes:
There is a special handling for numeric strings beginning with a "0". The special handling is triggered if either the left or right operand OK: $ perl -e 'print join(",", "01" .. "02"), "\n"' Strange: $ perl -e 'print join(",", "1" .. "02"), "\n"' With the patch below, Yves' new test cases pass (and all other tests) $ ./perl -e 'print join(",", "1" .. "02"), "\n"' Regards, Inline Patch--- /usr/local/src/bleedperl/pp_ctl.c Tue Oct 22 20:14:24 2002
+++ ./pp_ctl.c Wed Oct 30 15:45:46 2002
@@ -946,7 +946,7 @@ PP(pp_flop)
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)))
{
if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX)
DIE(aTHX_ "Range iterator outside integer range");
-- Slaven Rezic - slaven.rezic@berlin.de tknotes - A knotes clone, written in Perl/Tk. |
From @demerphqSlaven Rezic Sent on 30 October 2002 16:23
Aha!
Nice. :-) Yves |
From @jhiI think this issue got resolved, I'm marking the problem |
@jhi - Status changed from 'new' to 'resolved' |
Migrated from rt.perl.org#18114 (status was 'resolved')
Searchable as RT18114$
The text was updated successfully, but these errors were encountered: