bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Gawk 3.1.6 bug?


From: Aharon Robbins
Subject: Re: Gawk 3.1.6 bug?
Date: Tue, 24 Mar 2009 10:26:29 +0200

Hi. I don't know if I ever replied to this, for which I apologize.

> Subject: Gawk 3.1.6 bug?
> Date: Thu, 19 Feb 2009 15:33:48 -0500
> From: "Nielsen, Dan (GE, Corporate)" <address@hidden>
> To: <address@hidden>, <address@hidden>
>
> I don't know if this is a bug or not. Or, if it has already been reported.
>
> When I populate an array and test its length everything is fine. 
>
> However, if testing the length of array first then populating it I get the
> message
> "fatal: split: second argument is not an array"
> I suspect this is because arr as in length(arr) defines arr as a string then
> split("",arr) verifies that arr is indeed an array.

Your conclusion is correct. This is because awk is a dynamically typed
language: gawk deduces the type of a variable from its first use. Thus
you have to treat something as an array before calling length() on it
in order for length() to return the number of elements.

> BTW, both these examples work as desired under awk95 and Tawk.

That's because passing an array to length() is a gawk extension.
Newer versions of the Bell Labs awk support this extension too.
Hmmm:

$ nawk ' # array load then array length
>  # How to run: GAWK_3_1_6.EXE -f ZERROR9B.AWK
>  # error message: none
>  BEGIN {
>      f()
>      if (length(arr) == 0) { print("T") } else { print("F") }
>  }
>  function f() { split("1",arr) }
> '
F

OK, so far so good. Next:

$ nawk ' # array length then array load
>  # How to run: GAWK_3_1_6.EXE -f ZERROR9A.AWK
>  # error message: fatal: split: second argument is not an array
>  BEGIN {
>      if (length(arr) == 0) { print("T") } else { print("F") }
>      f()
>  }
>  function f() { split("1",arr) }
> '
T

So nawk is happy to ignore the fact that arr is untyped....

I think gawk is "more" correct here, but we're very much in
"dark corner" territory.

I will think about this some more.

Thanks,

Arnold




reply via email to

[Prev in Thread] Current Thread [Next in Thread]