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
Mark Overmeer
February 24, 2011 01:25
Re: [perl #84680] POSIX::isdigit() returns 1 for the empty string
Message ID:
* Robert Lang ( [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: >
> This is a bug report for perl from,
> 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  *

       Mark Overmeer MSc                                MARKOV Solutions                         

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About