nop has asked for the wisdom of the Perl Monks concerning the following question:
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 }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: is_numeric from perlfaq4
by Abigail-II (Bishop) on Oct 07, 2002 at 18:02 UTC | |
Re: is_numeric from perlfaq4
by thelenm (Vicar) on Oct 07, 2002 at 18:06 UTC | |
Re: is_numeric from perlfaq4
by fglock (Vicar) on Oct 07, 2002 at 18:08 UTC |