2008年11月22日星期六

Re: [PerlChina] China-pm Digest, Vol 43, Issue 26

thanks
gtalk:freeespeech@gmail.com

2008/11/23 <china-pm-request@pm.org>:
> Send China-pm mailing list submissions to
> china-pm@pm.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.pm.org/mailman/listinfo/china-pm
> or, via email, send a message with subject or body 'help' to
> china-pm-request@pm.org
>
> You can reach the person managing the list at
> china-pm-owner@pm.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of China-pm digest..."
>
>
> Today's Topics:
>
> 1. 传参的一点疑问 (owen nirvana)
> 2. Re: 传参的一点疑问 (bruce)
> 3. Re: 传参的一点疑问 (agentzh)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sat, 22 Nov 2008 12:49:56 +0800
> From: "owen nirvana" <freeespeech@gmail.com>
> Subject: [PerlChina] 传参的一点疑问
> To: china-pm@pm.org
> Message-ID:
> <ba5829cc0811212049q37002485gcb34fd1dfa8a4699@mail.gmail.com>
> Content-Type: text/plain; charset=GB2312
>
> 传递的参数是数组或者哈希的时候,怎么获取相关参数
>
> 比如 func ( @arr)或者func(%hash)
> 更复杂一点的
> func($param, @arr)
> func(@arr,%hash)
> 好像$_[0]肯定失灵了
>
> gtalk:freeespeech@gmail.com
>
> ------------------------------
>
> Message: 2
> Date: Sat, 22 Nov 2008 12:55:11 +0800
> From: "bruce" <bruce1914@gmail.com>
> Subject: Re: [PerlChina] 传参的一点疑问
> To: <china-pm@pm.org>
> Message-ID: <9D0C9F2F2A7948C2B0619A76AFC67925@brucelaptop>
> Content-Type: text/plain; charset="gb2312"
>
> 这种情况我一般用引用来解决,有点类似于C的指针。
>
> my @arr ;
> my %hash;
> $point_hash = \%hash ;
> $point_arr = \@arr ;
> func($point_arr) ;
> func2($point_hash) ;
>
> sub func
> { my ($point_arr) = @_ ;
> my @array_in = @{$point_arr} ;
> ...
> }
>
> sub func2
> { my ($point_hash) = @_ ;
> my %hash_in = %{$point_hash} ;
> ....
> }
>
>> -----Original Message-----
>> From: china-pm-bounces+bruce1914=gmail.com@pm.org
>> [mailto:china-pm-bounces+bruce1914=gmail.com@pm.org] On Behalf Of owen
>> nirvana
>> Sent: 2008年11月22日 12:50
>> To: china-pm@pm.org
>> Subject: [PerlChina] 传参的一点疑问
>>
>> 传递的参数是数组或者哈希的时候,怎么获取相关参数
>>
>> 比如 func ( @arr)或者func(%hash)
>> 更复杂一点的
>> func($param, @arr)
>> func(@arr,%hash)
>> 好像$_[0]肯定失灵了
>>
>> gtalk:freeespeech@gmail.com
>> _______________________________________________
>> China-pm mailing list
>> China-pm@pm.org
>> http://mail.pm.org/mailman/listinfo/china-pm
>
>
>
> ------------------------------
>
> Message: 3
> Date: Sat, 22 Nov 2008 15:19:49 +0800
> From: agentzh <agentzh@gmail.com>
> Subject: Re: [PerlChina] 传参的一点疑问
> To: china-pm@pm.org
> Message-ID:
> <c711ff240811212319w3a4d24eaj406300eb12226d04@mail.gmail.com>
> Content-Type: text/plain; charset="gb2312"
>
> 2008/11/22 owen nirvana <freeespeech@gmail.com>:
>> 传递的参数是数组或者哈希的时候,怎么获取相关参数
>>
>
> 以数组为参时:
>
> sub func {
> my @b = @_;
> # ...
> }
>
> my @a = (1,2,3);
> func(@a);
>
> 哈希为参时:
>
> sub func {
> my %b = @_;
> }
>
> my %a = (cat => 1, dog => 2);
> func(%a);
>
> 这里的行为是哈希和数组会自动平展成 @_ 中的离散元素 :) 如果想避免,可以使用数组和哈希的引用,例如:
>
> sub func {
> my @b = @{ $_[0] }
> # ...
> }
>
> my @a = (1,2,3);
> func(\@a);
>
> # OR func([1,2,3])
>
> 而对于哈希:
>
> my func {
> my %b = %{ $_[0] };
> # ...
> }
>
> my %a = (cat => 1, dog => 2);
> func(\%a);
>
> # OR func( { cat => 1, dog => 2 } );
>
> 参数是否 slurpy 的行为在 Perl 6 中可以更优雅地控制。。。呵呵
>
> Hope this helps :)
>
> -agentzh
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mail.pm.org/pipermail/china-pm/attachments/20081122/55d4eef4/attachment-0001.html>
>
> ------------------------------
>
> _______________________________________________
> China-pm mailing list
> China-pm@pm.org
> http://mail.pm.org/mailman/listinfo/china-pm
>
> End of China-pm Digest, Vol 43, Issue 26
> ****************************************
>
_______________________________________________
China-pm mailing list
China-pm@pm.org
http://mail.pm.org/mailman/listinfo/china-pm

没有评论: