Created
February 3, 2012 07:25
-
-
Save devoid/1728749 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# Test whether a scalar in perl is numeric or not. | |
# | |
# ( ( $i + 0 ) ne $i ) ? "not numeric" : "numeric"; | |
# | |
# - ` $i + 0 ` converts scalar to numeric | |
# - which should then not equal $i unless it is a numeric | |
# | |
use strict; | |
use String::Random qw(random_regex random_string); | |
print "value\tis a numeric\n"; | |
for my $i (qw(foo bar 1 2.3 -23.5 -2 0 -5bc b23 b23.5 23.b 5.5b bin inf nan -inf)) { | |
my $x = "yes"; | |
$x = "no" if(($i + 0) ne $i); | |
print "$i\t$x\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment