This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
C<undef> doesn't look like a number. See also:
authorMarcus Holland-Moritz <mhx-perl@gmx.net>
Mon, 15 Mar 2004 22:16:26 +0000 (23:16 +0100)
committerMarcus Holland-Moritz <mhx-perl@gmx.net>
Mon, 5 Apr 2004 20:03:03 +0000 (20:03 +0000)
Subject: Re: [perl #27606] undef "looks like" a number
Message-Id: <20040315221626.48061c67@r2d2>

p4raw-id: //depot/perl@22662

ext/List/Util/lib/List/Util.pm
ext/List/Util/lib/Scalar/Util.pm
ext/List/Util/t/lln.t
pp_ctl.c
sv.c

index 77a52f6..ff38fb4 100644 (file)
@@ -10,7 +10,7 @@ require Exporter;
 
 @ISA        = qw(Exporter);
 @EXPORT_OK  = qw(first min max minstr maxstr reduce sum shuffle);
-$VERSION    = "1.13";
+$VERSION    = "1.13_01";
 $XS_VERSION = $VERSION;
 $VERSION    = eval $VERSION;
 
index c2aabca..ad192a8 100644 (file)
@@ -11,7 +11,7 @@ require List::Util; # List::Util loads the XS
 
 @ISA       = qw(Exporter);
 @EXPORT_OK = qw(blessed dualvar reftype weaken isweak tainted readonly openhandle refaddr isvstring looks_like_number set_prototype);
-$VERSION   = "1.13";
+$VERSION   = "1.13_01";
 $VERSION   = eval $VERSION;
 
 sub export_fail {
index fe3ba4c..80b0996 100644 (file)
@@ -41,7 +41,7 @@ ok(!!looks_like_number("Inf"),            $] >= 5.006001);
 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),     $] < 5.009002);
 # That's enough - we trust the perl core tests like t/base/num.t
 
 __END__
index f0ac9fc..ec21e69 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1058,8 +1058,9 @@ PP(pp_flip)
 #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)
 {
diff --git a/sv.c b/sv.c
index c3a5a38..77ad8d0 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -1910,7 +1910,7 @@ Perl_looks_like_number(pTHX_ SV *sv)
     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);
 }