以下代码将吃掉@populations 中的内容
@populations=("EUR","AFR","ASN","AMR");
print @populations,"\n"; #will show EURAFRASNAMR
foreach (@populations)
{
$filepath="tmp.txt"; #whatever text file you like
open(FILE,"<$filepath");
while(<FILE>)
{
}
}
print @populations,"\n"; #will print nothing
如果更改为
foreach $i (@populations)
那么数组将不会被吃掉。
或者如果标记 while 循环,则数组不会被吃掉。
我不是 perl 大师,但有几年的经验。
谁能告诉我为什么?它是perl的错误吗?