Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
给定一个对象,我如何知道它在perl中的类?_Perl - Fatal编程技术网

给定一个对象,我如何知道它在perl中的类?

给定一个对象,我如何知道它在perl中的类?,perl,Perl,我需要这些信息来决定调用哪个具有特定方法的类。您可以使用内置函数来确定变量的引用类型或类: my $obj = bless [] => 'Some::Class'; print ref($obj), "\n"; # 'Some::Class'; 更多详细信息可以在Scalar::Util的reftype(始终返回容器类型)和founded(始终返回类名)子例程中找到。ref通常工作正常,但foundedin可能是更好的选择。它将返回undef,例如,对于没有被放入包中的普通引用。re

我需要这些信息来决定调用哪个具有特定方法的类。

您可以使用内置函数来确定变量的引用类型或类:

my $obj = bless [] => 'Some::Class';

print ref($obj), "\n";  # 'Some::Class';

更多详细信息可以在
Scalar::Util
reftype
(始终返回容器类型)和
founded
(始终返回类名)子例程中找到。

ref
通常工作正常,但
founded
in可能是更好的选择。它将返回
undef
,例如,对于没有被放入包中的普通引用。

ref($obj)
将为您完成这项工作