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: Robert Elz <kre%munnari.OZ.AU@localhost>
Subject: Re: bin/52623: nonsense error message in awk
Date: Mon, 16 Oct 2017 14:15:07 +0700

     Date:        Mon, 16 Oct 2017 02:05:00 +0000 (UTC)
     Message-ID:  <>
   | Accidentally writing index[array] instead of array[index] in awk
   | causes a nonsense error message.
 Not really nonsense...
   |    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.
 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.
   |    awk: can't assign to k; it's an array name.
 What would you have it do differently?

Home | Main Index | Thread Index | Old Index