How to access dynamic array var in AWK

How to access dynamic array var in AWK
0

#1

related thread about multi-step "for each" loops:

https://community.indeni.com/discussions/topics/45813?page=1


multitest.ind.txt

tupleError.txt


running command:

hawk@Tug:~/tmp/ind/src/checkpoint$ command-runner.sh full-command --ssh indeni,indenirocks123! multitest.ind 192.168.194.41

I'm trying to write a multi-step variable which holds a list of values (an array). I am able to create the variable and retrieve it in the second step, but then I can't seem to access the data in the variable -- it does not "act like" an AWK array. E.g., trying to do this:


for (key in theArr) {
debug(theArr[key])
}

Give me the error:

Description = Failed to compile AWK code of command "a-little-test-script". Code:
BEGIN {
    theArr = dynamic("myarr")
    debug("** length: " length(theArr))
writeComplexMetricString("dummy-metric", null, theArr)

for (key in theArr) {
debug(theArr[key])
}
},
Message = Failed to convert script to tuples. Script:

Interestingly, if I write the variable using writeComplexMetricString(), it succeeds and reports three metrics (the values of the “array”).


I’m guessing that the AWK variable type I’m ending up with in the second step isn’t an associative array, but I can’t figure out what it is. Dumping with writeDebug() “doesn’t work” – it seems to actually crash the script, but there’s no error message…I can’t quite tell what’s going on there…there’s a ton of DEBUG output, and I can see some of the values in the array (but not all), but this is all of the “>>><<< haystack” debug out that I don’t understand at all.


#2

The second step is being executed for every value in the “myarr” array; each time it is executed, it can access that (single) value via dynamic("myarr") which will return the string of that value.

For instance, if the first step generated a dynamic variable with 4 values: ["val1", "val2", "val3", "val4"] then the second step would be executed 4 times and each time the value of dynamic("myarr") would be one of these values.