[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Retrieve and In Bug?
From: |
Aharon Robbins |
Subject: |
Re: Retrieve and In Bug? |
Date: |
Mon, 19 Jul 2004 12:44:29 +0300 |
Greetings. This is not a bug. It is the way the awk
language is defined to work. The gawk doc thus describes
that `foo in a' is the right way to test for the existence
of a subscript, since `a[foo] != ""' has the side effect
of creating a[foo].
Thanks,
Arnold
> Date: Mon, 19 Jul 2004 11:26:28 +0200
> From: "Gerrit Riessen" <address@hidden>
> To: address@hidden
> Subject: Retrieve and In Bug?
> Organization: http://freemail.web.de/
>
> This is a MIME encoded message.
> --STEFAN40fb93c55672
> Content-Type: text/plain; charset="iso-8859-1"
> Content-Transfer-Encoding: 7bit
>
>
> Hello,
>
> I might have found a bug in the handling values that are not
> defined in arrays.
>
> Basically what I do is attempt to retrieve a value that is not
> defined as an index in an array, i.e. value = array[index]. This causes
> if the index is not defined, i.e. (index in array) returns 0, to define
> the index, i.e. (index in array) returns 1 after calling value = array[index].
>
> I've tested this on GNU/Linux with Gawk 3.1.0 and on Win2000 with
> Gawk 3.1.3. I've also included the test program.
>
> Cheers, Gerrit
>
>
> ________________________________________________________________
> Verschicken Sie romantische, coole und witzige Bilder per SMS!
> Jetzt neu bei WEB.DE FreeMail: http://freemail.web.de/?mc=021193
>
> --STEFAN40fb93c55672
> Content-Type: text/plain; name="retrieve_and_in_bug.gawk"
> Content-Transfer-Encoding: base64
> Content-Disposition: attachment; filename="retrieve_and_in_bug.gawk"
>
> # -*- awk -*-
> # test.gawk
> #
> # Author: Gerrit Riessen, address@hidden
> # Copyright (C) 2004 Gerrit Riessen
> # This code is licensed under the GNU Public License.
> # $Id$
> #
> BEGIN {
> a[1] = 1;
> a[2] = 2;
> print "Is 3 in a?: " (3 in a);
> for ( idx in a ) print idx " = " a[idx];
> v = a[3];
> print "Is 3 in a?: "(3 in a);
> for ( idx in a ) print idx " = " a[idx];
> exit;
> }
>
> #### Returns on Linux: (GNU Awk 3.1.0)
> # Is 3 in a?: 0
> # 1 = 1
> # 2 = 2
> # Is 3 in a?: 1
> # 1 = 1
> # 2 = 2
> # 3 =
>
> #### Returns on Win2000: (GNU Awk 3.1.3)
> # Is 3 in a?: 0
> # 1 = 1
> # 2 = 2
> # Is 3 in a?: 1
> # 1 = 1
> # 2 = 2
> # 3 =
>
>
> --STEFAN40fb93c55672--
- Re: Retrieve and In Bug?,
Aharon Robbins <=