At 12:16 PM 6/30/05 -0500, Joe Discenza wrote:
>I bet you're right that "eval($var) eq $var + 0" works; have you
benchmarked it against all the other (regex, e.g.) methods presented?
I haven't benchmarked it but I can garuntee that it's faster than a regex.
Anything's faster than that. ;) This should cover everything:
foreach $var ("1e7", 0, 5, "6", "0.00", -4, "abc", "f4fc") {
if ($var eq $var + 0) {
print "$var is a pure number\n";
}
elsif (eval $var eq $var + 0) {
print "$var is a number\n"
}
else {
print "$var is not a number\n";
}
}
1e7 is a number
0 is a pure number
5 is a pure number
6 is a pure number
0.00 is a number
-4 is a pure number
abc is not a number
f4fc is not a number
--
REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=--
"...ne cede males"
00000100
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs