[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
local local Statement
The local keyword is used to define variables within a compound
statement that are local to the compound statement and that disappear
when the compound statement is exited. The local keyword may be used
within any compound statement, but is especially useful in user-defined
functions as described later. Variables defined with the local keyword
may be assigned an initial value in the statement and multiple
variables may be defined with a single statement. If a variable is not
assigned an initial value, it is initialized to zero and the null
string just as global variables are initialized.
Thus:
local i, j = 12, k = substr(str,5);
will define three variables local to the enclosing compound statement:
1. i initialized to zero/null string,
2. j initialized to 12, and
3. k initialized to a substring of the variable 'str'
Local variables initialized explicitly in local statements may be
initialized to constants, the values of global variables, values
returned by built-in functions, values returned by user-defined
functions or previously defined local variables. If the value is set
to that of a previously defined local variable, the variable may not be
defined in the same local statement. Thus:
local k = 5;
local j = k;
is correct, but
local k = 5, j = k;
is not. In the latter case QTAwk will quietly assume that k is a
global variable.
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson