Consider this function:
function add_one(in_ar, each) { for (each in in_ar) { in_ar[each]++ } }
I would like to modify it such that if a second array is provided, it would be used instead of modifying the input array. I tried this:
function add_one(in_ar, out_ar, each) { if (out_ar) { for (each in in_ar) { out_ar[each] = in_ar[each] + 1 } } else { for (each in in_ar) { in_ar[each]++ } } } BEGIN { split("1 2 3 4 5", q) add_one(q, z) print z[3] }
but I get this result:
fatal: attempt to use scalar `z' as an array