- 论坛徽章:
- 0
|
按你的意思,结果应该是peas,turnip .
但实际上输出为peas.
example:
#!/usr/bin/perl -w
use strict;
my @ww=qw(peas barley turnip);
splice (@ww,1,1);
print join(' ',@ww);
输出结果为:
peas turnip
在这个例子中,结果输出正确。
#!/usr/bin/perl -w
use strict;
my @veg=qw(carrots corn);
splice (@veg,0,1);
print @veg,"\n";
splice (@veg,0,0,qw(peas));
print join(' ',@veg),"\n";
splice (@veg,-1,1,qw(barley,turnip));
print join(' ',@veg),"\n";
splice (@veg,1,1);
print join(' ',@veg),"\n";
为什么上面那个例子最后那条语句的输出会是peas呢?郁闷中!在执行splice(@veg,1,1);操作之前,@veg的值已被修改为
peas, barley,turnip 了。
[ 本帖最后由 hb12112 于 2006-3-26 01:08 编辑 ] |
|