[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] gawk: questions:
From: |
Andrew J. Schorr |
Subject: |
Re: [bug-gawk] gawk: questions: |
Date: |
Sun, 13 Jan 2013 18:34:10 -0500 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hi Denis,
On Sat, Jan 12, 2013 at 07:07:28PM +0200, Denis Shirokov wrote:
> I have some questions
>
> 1)Why:
> isarray(A[1]) - creates string element at A[1] if A was never defined
> as array nor string?
> BEGIN{
> if ( 1 in A ) print "A: is EXIST"
> if ( isarray(A[1]) ) print "B: is Array"
> if ( 1 in A ) print "C: is EXIST" }
> prints:
> C is EXIST
>
> This is not right. I just answer `A[1] is actually array?' - this
> question exactly means that element can be string or array or
> undefined - and if it's undefined - then it should be stay undefined.
Sorry, that's just not how it works. In your second test, you should say:
if ((1 in A) && isarray(A[1])) ...
Otherwise, your accessing A[1] creates the array element.
I think this is pretty well documented. There is no need to extend
the language; you simply must take care to use the "in" operator to
test before accessing an array element.
Regards,
Andy