我正在寫perl腳本,對於循環限制我沒有什麼問題。perl中的循環幫助
假設我有兩個數組,arr1有序列號,arr2是二維數組,第一個維度是序列號[與arr1相同],第二個維度是該序列號的內容,現在我想爲這個二維數組應用for循環,但我很困惑的極限。到現在我有這樣的代碼
Example : I have Three serial numbers , 1 ,2 ,3 . Serial 1 has 2 contents 1,5 . Serial 2 has 1 content i.e 1. Serial 3 has two contents 1,1.
@arr1 = (1,2,3)
$arr2[0][0] = 1
$arr2[0][1] = 5
$arr2[1][0] = 1
$arr2[2][1] = 1
$arr2[2][2] = 1
Note: As you can see the contents of arr2 has arr1 elements in 1st columns and the contents in the second columns.
for (my $i = 0; $i <= $#arr1; $i++) {
print("The First Serial number has:");
for (my $j = 0; $j <= $#arr2; $j++) {
print("$arr2[$i][$j]\n");
}
}
謝謝,對不起,我不好交代
謝謝你們所有人 – user2828488