awk - Unix, Linux Command---reference
Starting with version 3.1 of?gawk,the following functions may be used from within your AWK program for translating strings at run-time. For full details,see?GAWK: Effective AWK Programming.
Functions in?AWK?are defined as follows: function?name(parameter list) {?statements?} Functions are executed when they are called from within expressions in either patterns or actions. Actual parameters supplied in the function call are used to instantiate the formal parameters declared in the function. Arrays are passed by reference,other variables are passed by value. Since functions were not originally part of the?AWK?language,the provision for local variables is rather clumsy: They are declared as extra parameters in the parameter list. The convention is to separate local variables from real parameters by extra spaces in the parameter list. For example: <table class="src" cellspacing="5" cellpadding="5"> |
Functions may call each other and may be recursive. Function parameters used as local variables are initialized to the null string and the number zero upon function invocation.
Use?return?expr?to return a value from a function. The return value is undefined if no value is provided,or if the function returns by ‘‘falling off’’ the end.
If?--lint?has been provided,?gawk?warns about calls to undefined functions at parse time,instead of at run time. Calling an undefined function at run time is a fatal error.
The word?func?may be used in place of?function.
Beginning with version 3.1 of?gawk,you can dynamically add new built-in functions to the running?gawk?interpreter. The full details are beyond the scope of this manual page; see?GAWK: Effective AWK Programming?for the details.
(编辑:好传媒网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!