用for循环对每个数组元素重新赋值:
#!/usr/bin/perl @array = (1..30); print "@array\n"; for($i=0; $i<=$#array; $i++){ $array[$i] = $array[$i] + 10; } print "@array\n";
用while循环对每个数组元素重新赋值:
#!/usr/bin/perl @array = (1..30); $count = 1; print @array; while($count <= @array){ $array[$count - 1] += 10; $count++; } print @array;
用foreach循环对每个数组元素重新赋值:(foreach可以多多个数组进行操作)
#!/usr/bin/perl @array = (1..30); print "@array\n"; @array_1 = (31..60); foreach $item (@array,@array_1){ $item += 10; } print "@array\n"; print "@array_1\n"
时间: 2024-10-11 04:24:49