Blame test/funlen.awk

Packit 575503
# Date: Sat, 15 Mar 2008 16:21:19 +0100
Packit 575503
# From: Hermann Peifer <peifer@gmx.net>
Packit 575503
# Subject: [Fwd: Gawk length(array) bug]
Packit 575503
# To: bug-gawk@gnu.org
Packit 575503
# Cc: Aharon Robbins <arnold@skeeve.com>
Packit 575503
# Message-id: <47DBE96F.1060406@gmx.net>
Packit 575503
# 
Packit 575503
# See below. Regards, Hermann
Packit 575503
# 
Packit 575503
# -------- Original Message --------
Packit 575503
# Subject: Re: Gawk length(array) question
Packit 575503
# Date: Sat, 15 Mar 2008 08:02:03 -0500
Packit 575503
# From: Ed Morton <morton@lsupcaemnt.com>
Packit 575503
# Newsgroups: comp.lang.awk
Packit 575503
# References: <47DBAE29.4050709@gmx.eu>
Packit 575503
# 
Packit 575503
# On 3/15/2008 6:08 AM, Hermann Peifer wrote:
Packit 575503
# > Hi All,
Packit 575503
# > 
Packit 575503
# > The Gawk man page says:
Packit 575503
# >  > Starting with version 3.1.5, as a non-standard extension,
Packit 575503
# >  > with an array  argument, length() returns the number
Packit 575503
# >  > of elements in the array.
Packit 575503
# > 
Packit 575503
# > It looks like Gawk's length(array) extension does not work inside 
Packit 575503
# > functions. Is this a bug or feature or am I missing something? See the 
Packit 575503
# > example below. I am using GNU Awk 3.1.6
Packit 575503
# > 
Packit 575503
# > $ cat testdata
Packit 575503
# > CD NAME
Packit 575503
# > AT Austria
Packit 575503
# > BG Bulgaria
Packit 575503
# > CH Switzerland
Packit 575503
# > DE Germany
Packit 575503
# > EE Estonia
Packit 575503
# > FR France
Packit 575503
# > GR Greece
Packit 575503
# > 
Packit 575503
# > $ cat test.awk
Packit 575503
# > 
Packit 575503
# Populate array
Packit 575503
NR > 1 { array[$1] = $2 }
Packit 575503
Packit 575503
# Print array length and call function A
Packit 575503
END { print "array:",length(array) ; A(array) }
Packit 575503
Packit 575503
function A(array_A) { print "array_A:", length(array_A) }
Packit 575503
# > 
Packit 575503
# > $ gawk -f test.awk testdata
Packit 575503
# > array: 7
Packit 575503
# > gawk: test.awk:8: (FILENAME=data FNR=8) fatal: attempt to use array 
Packit 575503
# > `array_A (from array)' in a scalar context
Packit 575503
# > 
Packit 575503
# > BTW, there is no such error if I have asort(array_A) or asorti(array_A) 
Packit 575503
# > inside the function.
Packit 575503
# > 
Packit 575503
# > Hermann
Packit 575503
# 
Packit 575503
# I get the same result with gawk 3.1.6 for cygwin. Obviously you can work
Packit 575503
# around
Packit 575503
# it since asort() returns the number of elements in an array just like
Packit 575503
# length()
Packit 575503
# is supposed to (or "for (i in array) lgth++" if you don't want to be
Packit 575503
# gawk-specific) but it does seem like a bug. Anyone know if there's a list of
Packit 575503
# known gawk bugs on-line somewhere?
Packit 575503
# 
Packit 575503
# 	Ed.
Packit 575503
# 
Packit 575503
#