bug-gawk
[Top][All Lists]
Advanced

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

[bug-gawk] SYMTAB strangeness


From: Assaf Gordon
Subject: [bug-gawk] SYMTAB strangeness
Date: Fri, 14 Dec 2012 14:23:53 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.4) Gecko/20120510 Icedove/10.0.4

Hello,

(Continuing a previous discussion about SYMTAB: 
http://lists.gnu.org/archive/html/bug-gawk/2012-11/msg00023.html)

My goal is to add a little BEGIN code, that will read the first line from a 
file, create variables for each header/column name.

With the latest git revision, the following examples cause "internal error".

This works with latest revision - SYMTAB names are explicit:

    $ printf "Name Age\nJohn 30\nJane 40\n" | \
        gawk 'BEGIN { SYMTAB["Name"]=1 ; SYMTAB["Age"]=2 } { print $Age }'
    Age
    30
    40

This fails - SYMTAB names are read from a variable.
(but conceptually, IMHO, this seems equivalent to the previous example)

    $ printf "Name Age\nJohn 30\nJane 40\n" | \
        gawk 'BEGIN { getline ; for (i=1;i<=NF;++i) SYMTAB[$i]=i } { print $Age 
}'
    gawk: cmd. line:1: (FILENAME=- FNR=2) fatal: internal error line 175, file: 
interpret.h


Similarly strange (probably related):

"test" is printed as a valid variable:

    $ echo | gawk -d/dev/stdout '{ SYMTAB["test"]=1 } END { print $test }' | 
grep test
    test: 1

"test" is *not* printed as a valid variable

    $ echo | gawk -d/dev/stdout '{ SYMTAB["test"]=1 }' | grep test

This generates internal error:

    $ echo test | gawk -d/dev/stdout '{ SYMTAB[$1]=1 } END { print $test }' | 
grep test
    gawk: (FILENAME=- FNR=1) fatal error: internal error
    test


Thanks,
 -gordon







reply via email to

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