Created
December 9, 2014 21:19
-
-
Save shinchit/80df67912529b1b1f67b 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
use Scalar::Util qw/blessed/; | |
my $obj = new MyClass; | |
if (blessed($obj)) { | |
print "is MyClass object.", "¥n"; | |
print ref($obj); # you get class name (in this situation, you get MyClass) | |
} else { | |
print "is not any object.", "¥n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment