Hi Don,
Quote:
Originally Posted by
Don Cragun
I apologize for taking so long to get back to you. But when I have a choice between spending some time with the grandkids or evaluating an awk script; the grandkids are going to win every time.
Obviously absolutely no apology needed whatsoever. I hope you had a great time with your grandkids.
Quote:
Originally Posted by
Don Cragun
Do you understand now why we don't need to waste time or space assigning the index of each array element as the value of the array element as well instead of just using the index itself?
Yes. Thanks for the excellent explaination, now I get it.
Chubler_XL: My humblest apologies for taking your name in vain, and incorrectly stating that you were wrong when you wrote that
"the code never uses the value of the array element" - clearly you were not wrong, it was me that was wrong and I'm currently feeling somewhat guilty.
The problem was that I have seen this kind of loop construct so many times before:
for (ArrayElement in Array). In fact in something like half a dozen languages (PHP, Perl, Java, Python, JavaScript...) and always in the past it has meant to loop through all the elements of the array placing the value of the element in
ArrayElement. I've never come across that same construct but meaning
for (ArrayIndex in Array) before, and suspect this may be unique to Awk. I suppose it's not quite
not being able to see the forest for the trees but more like
not being able to see the trees for the forest.
Interestingly the Wikipedia Foreach loop page lists 33 languages which use the
for (ArrayElement in Array) type of loop and neither that page, nor the loop section of the Control flow page (both linked below), mention the Awk variation of the construct. I suppose Awk predates all of those languages and maybe even inspired the modern ForEach construct. Brian Kernighan is certainly a very clever man.
https://en.wikipedia.org/wiki/Foreach_loop
https://en.wikipedia.org/wiki/Loop_%...uting%29#Loops
Thanks for being so patient with me, best wishes and all that,
Gencon