Created
December 9, 2017 16:56
-
-
Save jef-sure/9d0914b6d47a75f139471bb464974849 to your computer and use it in GitHub Desktop.
Check for Positive Integer entry
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/perl | |
use B; | |
use Scalar::Util::LooksLikeNumber 'looks_like_number'; | |
sub positive_int { | |
my $lln = looks_like_number($_[0]); | |
($lln == 1 || $lln & B::SVf_IOK) && $_[0] > 0; | |
} | |
for (0, "0", 123, "123", 123.45, "123.45", "yolki-palki", "nancy") { | |
print "$_ -> " . (positive_int($_) ? "true" : "false"); | |
} | |
#0 -> false | |
#"0" -> false | |
#123 -> true | |
#"123" -> true | |
#123.45 -> false | |
#"123.45" -> false | |
#"yolki-palki" -> false | |
#"nancy" -> false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment