Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: I don't understand.

by davido (Cardinal)
on Nov 19, 2004 at 01:00 UTC ( [id://408923]=note: print w/replies, xml ) Need Help??


in reply to I don't understand.
in thread Detecting if a scalar has a number or string

Well, your regexp won't properly identify:

1.5 -3 -2.89 .32 0.5 -.01

...as numbers. It will also fail to reject empty strings.


Dave

Replies are listed 'Best First'.
Re^2: I don't understand.
by Anonymous Monk on Nov 05, 2008 at 16:07 UTC
    Ok, here's a bit of enhancement:
    foreach $abc ("asd","","0","123","-12","1.2","-1.2","12-","-a12","a1") {print "$abc:", is_a_num($abc) ? "Number" : "NaN", "\n";} sub is_a_num { return ($_[0] =~ /^(\+|-)?([0-9]|\.)+$/) || 0 ; }
    Thierry

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-24 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found