[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Possible bug in array handling after end of input (END handler)
From: |
Christian Schmidt |
Subject: |
Possible bug in array handling after end of input (END handler) |
Date: |
Fri, 4 Dec 2020 15:28:54 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 |
Dear gawk maintainers,
I stumbled across an unexpected behavior where a for (var in array)
construct encounters each array element twice if called from an END handler.
A small test case:
=== begin t.awk ===
function dump() {
for (i in vars) printf ("%s:%s ", i, vars[i]);
print;
delete vars;
}
(NF == 0) { dump(); }
(NF > 0) {
for (i=1; i<=NF; i++) {
split ($i, a, /:/);
vars[a[1]] = a[2];
}
}
END { dump(); }
=== end t.awk ===
=== begin data.txt ===
a:1 b:2
c:4
a:2 b:5 c:3
=== end data.txt ===
Resulting output:
awk -f t.awk data.txt
a:1 b:2 c:4
a:2 b:5 c:3 a:2 b:5 c:3
awk --version
GNU Awk 5.1.0, API: 3.0
If another empty line is added to the end of data.txt, the output
changes as expected:
awk -f t.awk data.txt
a:1 b:2 c:4
a:2 b:5 c:3
<blank line>
Best regards and looking forward for your help,
Chris
--
AIBIoT GmbH | CEO: Lukas Grunwald
Hornemannstraße 12 | HRB 206588
31137 Hildesheim | Amtsgericht Hildesheim
Germany
- Possible bug in array handling after end of input (END handler),
Christian Schmidt <=