Closed p5pRT closed 21 years ago
This program:
--------------------------------- @a = (1\, 2\, 3);
print $a["1foo"]\, "\n"; print $a["1"]\, "\n"; ---------------------------------
prints:
Argument "1foo" isn't numeric in array element at xxx.pl line 4. 1 2
With perl5.005_03 I get "2\n2\n" as expected.
gisle@aas.no (lists.p5p):
This program:
--------------------------------- @a = (1\, 2\, 3);
print $a["1foo"]\, "\n"; print $a["1"]\, "\n"; ---------------------------------
prints:
Argument "1foo" isn't numeric in array element at xxx.pl line 4. 1 2
Oh\, sheesh\, I am naughty. This is a bug I fixed in Sapphire but didn't backport to Perl. Sorry 'bout that. The problem is that sv_2iv calls looks_like_number to determine whether something can be converted to a number or not. looks_like_number is much stricter than the /^[\d.]+/ rule you'd imagine - it's actually more like /^[\d.]+\s*$/ with exceptions for infinity and "0 but true". Hence\, "1foo" doesn't match that\, and looks_like_number returns zero.
It's my contention that it shouldn't. The offending lines are 2039 and 2040 of sv.c:
if (s >= send) return numtype;
That enforces the \s*$ bit of the above regular expression: it says we have to have past the end of the string after we've dealt with the numbers and spaces.
This is what's in Sapphire:
simon@brecon.co.uk (Simon Cozens) writes:
gisle@aas.no (lists.p5p):
This program:
--------------------------------- @a = (1\, 2\, 3);
print $a["1foo"]\, "\n"; print $a["1"]\, "\n"; ---------------------------------
prints:
Argument "1foo" isn't numeric in array element at xxx.pl line 4. 1 2
Oh\, sheesh\, I am naughty. This is a bug I fixed in Sapphire but didn't backport to Perl. Sorry 'bout that. The problem is that sv_2iv calls looks_like_number to determine whether something can be converted to a number or not. looks_like_number is much stricter than the /^[\d.]+/ rule you'd imagine - it's actually more like /^[\d.]+\s*$/ with exceptions for infinity and "0 but true". Hence\, "1foo" doesn't match that\, and looks_like_number returns zero.
It's my contention that it shouldn't. The offending lines are 2039 and 2040 of sv.c:
if \(s >= send\) return numtype;
That enforces the \s*$ bit of the above regular expression: it says we have to have past the end of the string after we've dealt with the numbers and spaces.
I would argue that looks_like_number is correct. The problem is the stuff in sv_2iv which says /* Not a number. Cache 0. */. It should invoke Atol() or Atof() always.
Regards\, Gisle
This is what's in Sapphire:
--- sv.c~ Thu Aug 10 21:21:08 2000 +++ sv.c Thu Aug 10 21:21:40 2000 @@ -2036\,11 +2036\,9 @@ } while (isSPACE(*s)) s++; - if (s >= send) - return numtype; if (len == 10 && memEQ(sbegin\, "0 but true"\, 10)) return IS_NUMBER_TO_INT_BY_ATOL; - return 0; + return numtype; }
Gisle Aas (lists.p5p):
I would argue that looks_like_number is correct. The problem is the stuff in sv_2iv which says /* Not a number. Cache 0. */. It should invoke Atol() or Atof() always.
This is probably a bit philosophical\, but I think that the job of looks_like_number is to determine whether and how Ato*() should be invoked. looks_like_number should only return zero if something doesn't look like a number.
Could go either way\, I guess.
Gisle Aas \gisle@​ActiveState\.com wrote
I would argue that looks_like_number is correct. The problem is the stuff in sv_2iv which says /* Not a number. Cache 0. */. It should invoke Atol() or Atof() always.
I entirely agree\, not least because that's what 5.005_03 does.
Patch\, with regression test\, for bleadperl follows.
Mike Guy
I just wrote
Patch\, with regression test\, for bleadperl follows.
I forgot to add that in the two branches I merged\, one had a dTHR and the other did not. So I left it out in the merge\, but I don't understand the rules. The patch has only been tested without threads.
YMMV.
Mike Guy
On Thu\, Aug 10\, 2000 at 03:50:54PM +0100\, Mike Guy wrote:
Gisle Aas \gisle@​ActiveState\.com wrote
I would argue that looks_like_number is correct. The problem is the stuff in sv_2iv which says /* Not a number. Cache 0. */. It should invoke Atol() or Atof() always.
I entirely agree\, not least because that's what 5.005_03 does.
Patch\, with regression test\, for bleadperl follows.
It's in.
Migrated from rt.perl.org#3670 (status was 'resolved')
Searchable as RT3670$