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