Perl: class method and instance method

类函数调用

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";
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值