加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Perl: class method and instance method

发布时间:2020-12-15 20:54:50 所属栏目:大数据 来源:网络整理
导读:类函数调用 Class-method(@arg)===================Class::method('Class',@args); 第一个参数是类名称 ? 对象(实例)函数调用 Instance-method(@arg)=================Class::method(Instance,@arg); ?第一个参数是instace ? bless 的解释可参见 http://bbs2

类函数调用

Class->method(@arg)===================Class::method('Class',@args);

第一个参数是类名称

?

对象(实例)函数调用

Instance->method(@arg)=================Class::method(Instance,@arg);

?第一个参数是instace

?

bless的解释可参见

http://bbs2.chinaunix.net/viewthread.php?tid=981190

?

bless in perldoc

http://perldoc.perl.org/functions/bless.html

?

my $scalar;

my @array;

my %hash;

my $instance = /$scalar(/@array,%hash)

bless $instance $class;

?

ref in perldoc

http://perldoc.perl.org/functions/ref.html

?

ref EXPR

判断变量是否是reference

ref $either ? $$either????????? #this is a reference

????????????????? : "not ref";??????????#this is not a ref

如果EXPR是ref,返回一个非空字符串,反之返回空字符串。返回值依赖ref引用的类型。内嵌类型包括:

  1. ??? SCALAR
  2. ??? ARRAY
  3. ??? HASH
  4. ??? CODE
  5. ??? REF
  6. ??? GLOB
  7. ??? LVALUE
  8. ??? FORMAT
  9. ??? IO
  10. ??? VSTRING
  11. ??? Regexp

my $num = 0;
my $scaref = /$num;

if (ref $scaref eq "SCALAR")?{?print "this is a scalar reference./n";}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读