bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] SYMTAB strangeness


From: Aharon Robbins
Subject: Re: [bug-gawk] SYMTAB strangeness
Date: Sun, 16 Dec 2012 17:54:06 +0200
User-agent: Heirloom mailx 12.5 6/20/10

Hi Assaf.

Re the below.  I had already fixed these problems in one of the development
branches, which I had not yet merged to master.

I have just merged that branch to master, and added two of these scripts
to the test suite, and pushed it all up to Savannah.

If you do a 'git pull' you should find that these are working for you now.

As noted, you cannot create variables by adding them to SYMTAB at runtime.
Instead, SYMTAB gives you indirect access to the variables you use in
your program's text.  In addition, it acts as a regular associative array
(which may still be a mistake).  The -d option which dumps variables
distinguishes amongst the elements of SYMTAB that are real variables
and those that are not, and only dumps those that are.

Thanks!

Arnold

> 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]