bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Access variables not conforming to the variable naming co


From: Andrew J. Schorr
Subject: Re: [bug-gawk] Access variables not conforming to the variable naming convention?
Date: Mon, 3 Dec 2018 11:24:46 -0500
User-agent: Mutt/1.5.21 (2010-09-15)

On Mon, Dec 03, 2018 at 09:12:20AM -0700, address@hidden wrote:
> How does it stomp on the variable namespace?

I was merely pointing out that blindly setting values in SYMTAB
for column titles read from a data file could overwrite values
set by the program. Using my previous example:

bash-4.2$ cat inp
name,age,weight
John,23,150
Hilda,17,110
bash-4.2$ gawk -F, '
BEGIN {
   name = "junk"
}

NR == 1 {
   for (i = 1; i <= NF; i++)
      SYMTAB[$i] = i
   next
}

$age >= 20 {
   print
}

END {
   print name
}' inp
John,23,150
1

So the `name' variable was inadvertently(?) changed from junk to 1 due
to its presence as a column title in the file. 

In other words, I agree that this is a sloppy and dangerous coding style.
However, I am more hesitant about breaking existing, working code. If the
programmer wants to abuse SYMTAB, why should we stop him?

Regards,
Andy



reply via email to

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