有人可以解釋,爲什麼我沒有得到預期的結果?awk,自定義的delarray函數
awk '
# I know there is delete array, but this is more portable
# that is what docs are saying, anyway wanted to test it out.
function delarray(a, i)
{
for (i in a)
delete a[i]
}
BEGIN {
a[3]=""
a[4]=""
for (e in a)
print e
delarray(a)
for (e in a)
print ".."
print e
}
'
執行上面的腳本,我期望看到:
3
4
..(nothing here)
我以前..
想法,我不會看到任何東西,因爲 刪除陣列值,這樣正好看到..
爲佔位符)
,但實際輸出我看到的是:
3
4
4 #(why this?, and where are two dots?)
,退出代碼爲1,爲什麼?
無論你正在閱讀什麼文檔,說創建該函數是「刪除數組」的替代方法,將它們扔掉。 'split(「」,array)'是'delete array'的可移植替代。 –