谢谢!

2009/1/19 Changying Li <[email protected]>

> 这个没人回答?我来答一下
> 我没找到关于for的文档,谁知道也回复一下
> for(@array)里,$_是一个就地修改的变量(忘了perl里叫啥名字了),它其实是
> @array的元素的一个别名,相当于:
> for ($i=0;$i <= $#array;$i++){
>    *_ = *{$array[$i]}; #是这样写吗?
>    push @array_2, shift @array;
> }
>
> 每次循环, $i 增1, $#array减1,所以只循环了3次,而shift和$i无关,所...@array
> 只shift出了a b c,剩下 d e f
>
> zhang jy <[email protected]> writes:
>
> > hi~
> >       大家好!最近在工作中遇到了一个问题。
> > #!perl -w
> > use strict;
> > my @array=('a','b','c','d','e','f');
> > my @array_2;
> > for(@array)
> > {
> >       push @array_2,shift @array;
> > }
> > for(@array)
> > {
> >     print $_;
> > }
> >
> > 我希望看到的...@array内被清空,@array_2被填满。可是情况确...@array中存在d,e,f。
> > 请教一下大家,如何才能达到我想要的目的?
> > 还有,为什么存在的是def,而不是b.d.f
> > 谢谢!
> >
> > >
>
> --
>
> Thanks & Regards
>
> Changying Li
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛“PerlChina 论坛”论坛。
 要在此论坛发帖,请发电子邮件到 [email protected]
 要退订此论坛,请发邮件至 [email protected]
 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛
-~----------~----~----~----~------~----~------~--~---

回复