Next: I18N Functions, Previous: Bitwise Functions, Up: Built-in [Contents][Index]
gawk
provides a single function that lets you distinguish
an array from a scalar variable. This is necessary for writing code
that traverses every element of an array of arrays
(see Arrays of Arrays).
isarray(x)
Return a true value if x is an array. Otherwise, return false.
isarray()
is meant for use in two circumstances. The first is when
traversing a multidimensional array: you can test if an element is itself
an array or not. The second is inside the body of a user-defined function
(not discussed yet; see User-defined), to test if a parameter is an
array or not.
NOTE: Using
isarray()
at the global level to test variables makes no sense. Because you are the one writing the program, you are supposed to know if your variables are arrays or not. And in fact, due to the waygawk
works, if you pass the name of a variable that has not been previously used toisarray()
,gawk
ends up turning it into a scalar.