gawk: Multiscanning
1
1 8.5.1 Scanning Multidimensional Arrays
1 --------------------------------------
1
1 There is no special 'for' statement for scanning a "multidimensional"
1 array. There cannot be one, because, in truth, 'awk' does not have
1 multidimensional arrays or elements--there is only a multidimensional
1 _way of accessing_ an array.
1
1 However, if your program has an array that is always accessed as
1 multidimensional, you can get the effect of scanning it by combining the
1 scanning 'for' statement (⇒Scanning an Array) with the built-in
1 'split()' function (⇒String Functions). It works in the
1 following manner:
1
1 for (combined in array) {
1 split(combined, separate, SUBSEP)
1 ...
1 }
1
1 This sets the variable 'combined' to each concatenated combined index in
1 the array, and splits it into the individual indices by breaking it
1 apart where the value of 'SUBSEP' appears. The individual indices then
1 become the elements of the array 'separate'.
1
1 Thus, if a value is previously stored in 'array[1, "foo"]', then an
1 element with index '"1\034foo"' exists in 'array'. (Recall that the
1 default value of 'SUBSEP' is the character with code 034.) Sooner or
1 later, the 'for' statement finds that index and does an iteration with
1 the variable 'combined' set to '"1\034foo"'. Then the 'split()'
1 function is called as follows:
1
1 split("1\034foo", separate, "\034")
1
1 The result is to set 'separate[1]' to '"1"' and 'separate[2]' to
1 '"foo"'. Presto! The original sequence of separate indices is
1 recovered.
1