Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: is_numeric

by Fletch (Bishop)
on Apr 12, 2007 at 14:26 UTC ( [id://609676]=note: print w/replies, xml ) Need Help??


in reply to Re^2: is_numeric
in thread is_numeric

But you've turned off the warning telling you that it doesn't looks_like_number. If you don't have warnings on, Perl assumes you know what you're doing and tries to do what you've asked it to with the (crummy) numberish data you've given it. If you have enabled warnings, it lets you know about it's misgivings but still goes ahead and does what you've asked.

I think the expectation mismatch is because Perl uses the (POSIX) C strtod(3) which by design (or at least by the manual page description :) follows this heuristic (from the start of the char* passed parse off as many digits followed by an optional "." and more digits followed by an optional exponent notation, and stop when you hit a not-digit-not-plusminus-not-exponent-marker character) rather than using if-looks_like_number-number-else-it's-zero. This is mentioned in perldata in passing, but if you're not familiar with the C API I'll grant that it's certainly open to causing confusion.

Replies are listed 'Best First'.
Re^4: is_numeric
by ysth (Canon) on Apr 12, 2007 at 18:31 UTC
    It used to use strtod, but doesn't any more. The C99 standard pulled the rug out from under everyone by changing e.g. "0x10" from being 0 (in C89) to being 16.

      Ooop, you're quite right. Perhaps perldata shouldn't mention strtod as a way to check for numerical-ness then. Of course if you're getting hex numbers as strings you're going to need to convert them (through POSIX::strtod or hex) anyhow before they're interpreted as the correct value so maybe it's kind of a corner case.

      Good point though.

Re^4: is_numeric
by ology (Initiate) on May 02, 2009 at 17:43 UTC
    You are The Man.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://609676]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-24 07:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found