Skip to content

Instantly share code, notes, and snippets.

@jef-sure
Created December 9, 2017 16:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jef-sure/9d0914b6d47a75f139471bb464974849 to your computer and use it in GitHub Desktop.
Save jef-sure/9d0914b6d47a75f139471bb464974849 to your computer and use it in GitHub Desktop.
Check for Positive Integer entry
#!/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