develooper Front page | perl.perl5.porters | Postings from February 2011

Re: [perl #84680] POSIX::isdigit() returns 1 for the empty string

Thread Previous | Thread Next
From:
Mark Overmeer
Date:
February 24, 2011 01:25
Subject:
Re: [perl #84680] POSIX::isdigit() returns 1 for the empty string
Message ID:
20110224092517.GO24256@moon.overmeer.net
* Robert Lang (perlbug-followup@perl.org) [110224 08:33]:
> # New Ticket Created by  Robert Lang 
> # Please include the string:  [perl #84680]
> # in the subject line of all future correspondence about this issue. 
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=84680 >
> 
> 
> This is a bug report for perl from perlbug@cg.cjb.net,
> generated with the help of perlbug 1.39 running under perl 5.12.3.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> POSIX::isdigit() returns 1 for the empty string which is
> obviously wrong:
> 
> $ perl -MPOSIX -e 'print isdigit(""), "\n"'
> 1
> $
> 
> That's probably because RETVAL is initialised to 1 in POSIX.xs
> regardless of the string length (which is the case in all is*()
> functions ...).

Although POSIX.pod says:

    isdigit This is identical to the C function, except that it can apply
            to a single character or to a whole string. 

that is not true. There is very little the same as in the C function
with the same name.

The real way the implementation should be described is more like:

    isdigit  Returns false if the string only contains digits.

All these "isXXXX" functions are implemented that way.
Of course, with the correct description in the POD, this result is
logical: the empty string does not contain any conflicting characters.

  *  DO NOT USE POSIX::isdigit() but regexes  *
-- 
Regards,
               MarkOv

------------------------------------------------------------------------
       Mark Overmeer MSc                                MARKOV Solutions
       Mark@Overmeer.net                          solutions@overmeer.net
http://Mark.Overmeer.net                   http://solutions.overmeer.net


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About