for loop in perl

前端 未结 4 1635
灰色年华
灰色年华 2021-01-22 15:35
my @array=(1..10);
for my $i (@array){$i++;}
print \"array is now:@array\";

this is changing the values of the array. Why?

4条回答
  •  猫巷女王i
    2021-01-22 16:09

    The loop variable $i is aliased to each element in the array in turn.

    That means that if you change $i you're changing the array.

提交回复
热议问题