gawk: Arrays Summary
8.7 Summary
===========
* Standard 'awk' provides one-dimensional associative arrays (arrays
indexed by string values). All arrays are associative; numeric
indices are converted automatically to strings.
* Array elements are referenced as 'ARRAY[INDX]'. Referencing an
element creates it if it did not exist previously.
* The proper way to see if an array has an element with a given index
is to use the 'in' operator: 'INDX in ARRAY'.
* Use 'for (INDX in ARRAY) ...' to scan through all the individual
elements of an array. In the body of the loop, INDX takes on the
value of each element's index in turn.
* The order in which a 'for (INDX in ARRAY)' loop traverses an array
is undefined in POSIX 'awk' and varies among implementations.
'gawk' lets you control the order by assigning special predefined
values to 'PROCINFO["sorted_in"]'.
* Use 'delete ARRAY[INDX]' to delete an individual element. To
delete all of the elements in an array, use 'delete ARRAY'. This
latter feature has been a common extension for many years and is
now standard, but may not be supported by all commercial versions
of 'awk'.
* Standard 'awk' simulates multidimensional arrays by separating
subscript values with commas. The values are concatenated into a
single string, separated by the value of 'SUBSEP'. The fact that
such a subscript was created in this way is not retained; thus,
changing 'SUBSEP' may have unexpected consequences. You can use
'(SUB1, SUB2, ...) in ARRAY' to see if such a multidimensional
subscript exists in ARRAY.
* 'gawk' provides true arrays of arrays. You use a separate set of
square brackets for each dimension in such an array:
'data[row][col]', for example. Array elements may thus be either
scalar values (number or string) or other arrays.
* Use the 'isarray()' built-in function to determine if an array
element is itself a subarray.