-
Notifications
You must be signed in to change notification settings - Fork 561
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
undef "looks like" a number #7168
Comments
From zefram@fysh.orgCreated by zefram@fysh.org$ perl -MScalar::Util=looks_like_number -we 'print looks_like_number(undef), " ", 0+undef,"\n"' looks_like_number() returns true for undef, even though Perl actually I guess this is related to the "return 1; /* Historic. Wrong? */" Perl Info
|
From @mhxOn 2004-03-12, at 19:54:36 -0000, Zefram (via RT) wrote:
Yes, it's related to that line. The comment was added by this patch: Change 10463 by jhi@alpha on 2001/06/06 23:15:30 The line itself seems to be _very_ old. The current behaviour is strange ok(!!looks_like_number(undef), 1); However, there was a recent discussion about undef, which revealed... Chip Salzenberg <chip@pobox.com> wrote:
Chip Salzenberg <chip@pobox.com> wrote:
So, it seems there's at least one other exception: looks_like_number() Even though it could be "fixed" easily, I'm not sure if it should be. Marcus -- Yes, yes, its called a design limitation |
The RT System itself - Status changed from 'new' to 'open' |
From zefram@fysh.orgAddendum: typeglobs suffer the same problem: $ perl -MScalar::Util=looks_like_number -we 'print looks_like_number(*foo), " ", 0+*foo,"\n"' -zefram |
From @rgsMarcus Holland-Moritz wrote:
Difficult to say without knowing the implications; a quick inspection |
From @mhxOn 2004-03-14, at 22:30:37 +0100, Rafael Garcia-Suarez wrote:
The attached patch should do it. At least it doesn't Apply at your own risk ;-) -- |
From @mhxlln.diff--- sv.c.orig 2004-03-14 02:25:46.000000000 +0100
+++ sv.c 2004-03-14 02:29:30.000000000 +0100
@@ -1909,7 +1909,7 @@
else if (SvPOKp(sv))
sbegin = SvPV(sv, len);
else
- return 1; /* Historic. Wrong? */
+ return SvFLAGS(sv) & (SVf_NOK|SVp_NOK|SVf_IOK|SVp_IOK);
return grok_number(sbegin, len, NULL);
}
--- pp_ctl.c.orig 2004-03-15 19:50:40.000000000 +0100
+++ pp_ctl.c 2004-03-15 21:53:08.000000000 +0100
@@ -1058,8 +1058,9 @@
#define RANGE_IS_NUMERIC(left,right) ( \
SvNIOKp(left) || (SvOK(left) && !SvPOKp(left)) || \
SvNIOKp(right) || (SvOK(right) && !SvPOKp(right)) || \
- (((!SvOK(left) && SvOK(right)) || (looks_like_number(left) && \
- SvPOKp(left) && *SvPVX(left) != '0')) && looks_like_number(right)))
+ (((!SvOK(left) && SvOK(right)) || ((!SvOK(left) || \
+ looks_like_number(left)) && SvPOKp(left) && *SvPVX(left) != '0')) \
+ && (!SvOK(right) || looks_like_number(right))))
PP(pp_flop)
{
--- ext/List/Util/t/lln.t.orig 2004-03-15 21:04:53.000000000 +0100
+++ ext/List/Util/t/lln.t 2004-03-15 21:10:33.000000000 +0100
@@ -41,7 +41,7 @@
ok(!!looks_like_number("Infinity"), $] >= 5.008);
ok(!!looks_like_number("NaN"), $] >= 5.008);
ok(!!looks_like_number("foo"), '');
-ok(!!looks_like_number(undef), 1);
+ok(!!looks_like_number(undef), '');
# That's enough - we trust the perl core tests like t/base/num.t
__END__
|
From @rgsMarcus Holland-Moritz wrote:
I think you're welcome to apply this, after you've adjusted ext/List/Util/t/lln.t |
From @smpeters
It appears that this change was applied with change #22662. |
@smpeters - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#27606 (status was 'resolved')
Searchable as RT27606$
The text was updated successfully, but these errors were encountered: