bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] isarray() is assigning a type to its argument


From: Wolfgang Laun
Subject: Re: [bug-gawk] isarray() is assigning a type to its argument
Date: Sat, 13 May 2017 15:26:27 +0200

It's not the isarray that is to blame, it is referencing a[1] that creates a[1], necessarily as a scalar. It's a variant of the hen-egg problem.

The more cumbersome isarray(1 in a ? a[1] : 0) avoids this.

-W



On 13 May 2017 at 14:47, Ed Morton <address@hidden> wrote:
wrt this code:

awk 'BEGIN {
    a[1][2] = 7
    print "value:", a[1][2]
}'
value: 7

I did not expect that testing whether or not a[1] was an array first would force a[1] to be a scalar thereafter:

awk 'BEGIN {
    print "isarray:", isarray(a[1])
    a[1][2] = 7
    print "value:", a[1][2]
}'
isarray: 0
awk: cmd. line:3: fatal: attempt to use scalar `a["1"]' as an array

To me that's like if the "in" operator in an "if" condition caused the value to be present in an array, i just want to test for something, not affect it. Is that a bug or a design decision?

$ gawk --version | head -2
GNU Awk 4.1.4, API: 1.1 (GNU MPFR 3.1.5, GNU MP 6.1.2)
Copyright (C) 1989, 1991-2016 Free Software Foundation.

$ bash --version | head -2
GNU bash, version 4.4.12(3)-release (x86_64-unknown-cygwin)
Copyright (C) 2016 Free Software Foundation, Inc.

Regards,

    Ed.



reply via email to

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