NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/52623: nonsense error message in awk
The following reply was made to PR bin/52623; it has been noted by GNATS.
From: David Holland <dholland-bugs%netbsd.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc:
Subject: Re: bin/52623: nonsense error message in awk
Date: Mon, 16 Oct 2017 17:28:30 +0000
On Mon, Oct 16, 2017 at 07:20:01AM +0000, Robert Elz wrote:
>> awk -F: < /etc/passwd '{ a[$1] = $3; } END { for (k in a) print k[a]; }'
>
> When that is compiled, awk can see from the reference to k[a] that k is
> an array. The syntax is all OK, so the compile succeeds.
It's doing type inference?
> When it is executed, and we get to the "for (k in a)" we need to assign
> the indexes of array a to k, which can't be done, as k is an array.
>
> Hence:
>> awk: can't assign to k; it's an array name.
>
> What would you have it do differently?
I would expect it to, on the first iteration, assign k to the first
value in a[], then choke at the print where it tries to use an array
to index an array expression and/or tries to index an array as a
scalar.
e.g.
awk: can't read value of a; it's an array name.
--
David A. Holland
dholland%netbsd.org@localhost
Home |
Main Index |
Thread Index |
Old Index