On Thu, Dec 10, 2009 at 11:14:46AM +0800, Michael Zeng wrote: >不行吧,你要写 wowo(\...@a , \...@b ) > >或者 wowo($a, $b) , 而 $a, $b本身就是ref变量 > >sub里面都是靠 shift 来进行标量处理参数的 >
这样的啊, $a, $b是数组的元素个数吧, 在这个context下也表示数组本身的reference? > > >2009/12/10 Xiaojun Deng <[email protected]> > >> On Thu, Dec 10, 2009 at 10:48:39AM +0800, cnhack TNT wrote: >> >楼上正解,想要哈希或数组作为子程序的参数,请传递它们的引用给子程序 >> > >> >> 如同c的指针 >> Perl默认能传数组给函数吗? >> >> >2009/12/10 Michael Zeng <[email protected]> >> > >> >> 是应该用引用 >> >> >> >> 这样写传参数很晦涩, 特别是传数组的时候,而且开销很大,如...@list很大的时候 >> >> >> >> >> >> >> >> sub check{ >> >> my @d...@_[0]; >> >> my @n...@_[1]; >> >> my $n=0; >> >> for(my $i=0;$i<@num;$i++){ >> >> if($dd[$num[$i]] ne 'NA'){ >> >> $n++; >> >> } >> >> } >> >> return $n; >> >> } >> >> >> >> 用引用会比较清晰 >> >> >> >> 2009/12/10 钟声 <[email protected]> >> >> >> >> 引用应该可以的 >> >>> >> >>> $a = \...@one; >> >>> $b =...@two; >> >>> check($a,$b); >> >>> >> >>> >> >>> sub check { >> >>> my ($num,$dd) = @_; >> >>> $num->[0]; >> >>> $dd ->[0]; >> >>> >> >>> } >> >>> >> >>> 2009/12/10 camelbbs <[email protected]> >> >>> >> >>> 请问我的子程序想处理两个数组参数,应该怎么写,下面这样好像不行: >> >>>> >> >>>> sub check{ >> >>>> my @dd=shift; >> >>>> my @num=shift; >> >>>> my $n=0; >> >>>> for(my $i=0;$i<@num;$i++){ >> >>>> if($dd[$num[$i]] ne 'NA'){ >> >>>> $n++; >> >>>> } >> >>>> } >> >>>> return $n; >> >>>> } >> >>>> >> >>>> >> >>>> >> >>> >> >>> >> >>> >> >> >> >> >> >> -- >> >> Yours Sincerely >> >> Zeng Hong >> >> >> >> > >> >> >> > >> >> >> >> >> >> > > >-- > Yours Sincerely > Zeng Hong --~--~---------~--~----~------------~-------~--~----~ 您收到此信息是由于您订阅了 Google 论坛“PerlChina Mongers 讨论组”论坛。 要在此论坛发帖,请发电子邮件到 [email protected] 要退订此论坛,请发邮件至 [email protected] 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛 -~----------~----~----~----~------~----~------~--~---
