Hi -- I grabbed the is_numeric function from perfaq4. Either I am using it wrong, or it doesn't work. The following code asserts that undef and fish are numeric.
What's going wrong? Thanks --
nop
use POSIX qw(strtod);
use strict;
foreach (undef, qw(4 0 fish)) {
print $_ , " is numeric? ", is_numeric($_), "\n";
}
sub getnum {
my $str = shift;
$str =~ s/^\s+//; $str =~ s/\s+$//; $! = 0;
my($num, $unparsed) = strtod($str);
if (($str eq '') || ($unparsed != 0) || $!) {return;} else {return
+ $num;}
}
sub is_numeric { defined scalar &getnum }