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

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

Gawk Error


From: ghofulpo
Subject: Gawk Error
Date: Fri, 5 Nov 2010 14:08:27 -0700 (PDT)

Using Gawk 3.1.8

I run the following script, and get the corresponding output:

bash-3.2$ cat awkhate.awk
BEGIN {
    a[1] = "hi"
    if ( a[2] != "" ) print a[2]
    for ( inx in a )
    {
        print inx " " a[inx]
    }
}
bash-3.2$ gawk -f awkhate.awk
1 hi
2
bash-3.2$

It seems when I reference a[2] (which hasn't been created), it gets created 
automatically.  I would have expected the behavior of:
if ( a[2] != "" )
to be the same as
if ( 2 in a )

Thanks.

James


reply via email to

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