Last active
August 29, 2015 14:10
-
-
Save shinchit/5268872f317559af2094 to your computer and use it in GitHub Desktop.
Perlのスカラ変数で値が数値かどうか判定する方法
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
use strict; | |
use Scalar::Util qw/looks_like_number/; | |
my $var1 = 123; | |
my $var2 = 'abc'; | |
if (looks_like_number($var1)) { | |
# $var1は数値なのでif文はtrueになる | |
print "数値です", "¥n"; | |
} | |
if (looks_like_number($var2)) { | |
#$var2は数値ではないのでif文はfalseになる | |
} else { | |
print "数値ではありません", "¥n"; | |
} | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment