gawk: Dynamic Typing
1
1 9.2.5 Functions and Their Effects on Variable Typing
1 ----------------------------------------------------
1
1 'awk' is a very fluid language. It is possible that 'awk' can't tell if
1 an identifier represents a scalar variable or an array until runtime.
1 Here is an annotated sample program:
1
1 function foo(a)
1 {
1 a[1] = 1 # parameter is an array
1 }
1
1 BEGIN {
1 b = 1
1 foo(b) # invalid: fatal type mismatch
1
1 foo(x) # x uninitialized, becomes an array dynamically
1 x = 1 # now not allowed, runtime error
1 }
1
1 In this example, the first call to 'foo()' generates a fatal error,
1 so 'awk' will not report the second error. If you comment out that
1 call, though, then 'awk' does report the second error.
1
1 Usually, such things aren't a big issue, but it's worth being aware
1 of them.
1