Hi All,
The Gawk man page says:
> Starting with version 3.1.5, as a non-standard extension,
> with an array argument, length() returns the number
> of elements in the array.
It looks like Gawk's length(array) extension does not work inside
functions. Is this a bug or feature or am I missing something? See the
example below. I am using GNU Awk 3.1.6
$ cat testdata
CD NAME
AT Austria
BG Bulgaria
CH Switzerland
DE Germany
EE Estonia
FR France
GR Greece
$ cat test.awk
# Populate array
NR > 1 { array[$1] = $2 }
# Print array length and call function A
END { print "array:",length(array) ; A(array) }
function A(array_A) { print "array_A:", length(array_A) }
$ gawk -f test.awk testdata
array: 7
gawk: test.awk:8: (FILENAME=data FNR=8) fatal: attempt to use array
`array_A (from array)' in a scalar context
BTW, there is no such error if I have asort(array_A) or asorti(array_A)
inside the function.
Hermann