其实只要判断一下第一个参数是否 ref 就可以了,如果 ref 为真就 shift 掉它: shift if ref ($_[0])
2009/2/27 mark <[email protected]> > 谢谢,只是我想,建包是想将我的自己编的函数归类。我发现$max=MK1::max($zhu,$mark); > 传值就对啦,有没有别的解决办法? > > On 2月26日, 下午12时59分, purl lamp <[email protected]> wrote: > > 这是因为你使用了 OO 特性,就使得第一个参数成了对象或类的描述。这里的逻辑很简单,看不出使用 ->max 的理由。 > > 直接使用标准 sub 就 ok 了,从而不必 shift 掉第一个 reference 或者类名。 > > > > 2009/2/26 mark <[email protected]> > > > > > > > > > > > > > #tt.pl > > > use strict; > > > use warnings; > > > use PM::MK1; > > > my ($zhu,$mark)=(1333,122222); > > > my $max=MK1->max($zhu,$mark); > > > print "3:MAX:$max\n"; > > > > > #我的包文件MK1.pm > > > package MK1; > > > sub max{ > > > shift(@_); > > > my($temp1,$temp2)=...@_; > > > print "2:$temp1 ***$temp2\n"; > > > if($temp1 > $temp2){ > > > return $temp1; > > > }else{ > > > return $temp2; > > > } > > > } > > > > > return 1; > > > > > 如果我没用"shift(@_); " ,$temp1=MK1; > > > 我不知道为什么?- 隐藏被引用文字 - > > > > - 显示引用的文字 - > > > --~--~---------~--~----~------------~-------~--~----~ 您收到此信息是由于您订阅了 Google 论坛“PerlChina Mongers 讨论组”论坛。 要在此论坛发帖,请发电子邮件到 [email protected] 要退订此论坛,请发邮件至 [email protected] 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛 -~----------~----~----~----~------~----~------~--~---
