Skip to content

Instantly share code, notes, and snippets.

@shinchit
Last active August 29, 2015 14:10
Show Gist options
  • Save shinchit/5268872f317559af2094 to your computer and use it in GitHub Desktop.
Save shinchit/5268872f317559af2094 to your computer and use it in GitHub Desktop.
Perlのスカラ変数で値が数値かどうか判定する方法
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