I'm pretty new to awk/gawk and I found this a little confusing. I hope you may help me shed some light on this question: Are strings in awk treated as array of chars?
I've read something about the stringy-ness of this computing language, so I tried to make a script like this:
BEGIN {
myArray[1] = "foo"
myArray[2] = "bar"
myArray[3] = 42
awkward()
}
function awkward() {
for (j in myArray) {
for (d in myArray[j]) {
# error!
}
}
}
Was I naive in thinking something like this could work? It actually does not work with my version of gawk
, giving me this error:
for (d in myArray[j]) {
^ syntax error
Can anybody help me to understand more about why this should not work? Bonus: can anybody share their workaround on this?
To clarify a bit, I'm trying to access the content of myArray[j]
char by char, using a for loop on index d
.