使用 GNU Awk 5.1.0 时,以下内容会引发错误:
$ awk 'BEGIN {tmp[1]; delete tmp; tmp = ""}' --
awk: cmd. line:1: fatal: attempt to use array `tmp' in a scalar context
显然,delete
语句不会删除不能作为标量变量回收的变量的数组限定符。有办法获得吗?
最佳答案
Apparently the
delete
statement does not delete the array qualifier of the variable which cannot be recycled as a scalar variable.
描述时的 GNU AWK 用户指南 Delete说的是
CAUTION: Deleting all the elements from an array does not change its type; you cannot clear an array and then use the array’s name as a scalar (i.e., a regular variable). For example, the following does not work:
a[1] = 3 delete a a = 3
关于awk - 如何删除数组并为标量变量重用相同的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76820986/