Next: , Previous: , Up: Built-in   [Contents][Index]

9.1.7 Getting Type Information

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).


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 way gawk works, if you pass the name of a variable that has not been previously used to isarray(), gawk ends up turning it into a scalar.