explain

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 代码 · 共 88 行

TXT
88
字号
Nov 30, 1979:Awk has been modified yet again, in an attempt to makeits behavior more rational and predictable in the areasof initialization, comparison, and type coercion.Herewith what we believe the current truth to be:1. Each variable and field can potentially be a stringor a number or both at any time.When a variable is set by the assignment	v = exprits type is set to that of expr.  (This includes +=, ++, etc.)An arithmetic expression is of type number, aconcatenation is of type string,  and so on.If the assignment is a simple copy, as in	v1 = v2then the type of v1 becomes that of v2.2. In comparisons, if both operands are numeric,the comparison is made numerically.  Otherwise,operands are coerced to string if necessary, andthe comparison is made on strings.3. The type of any expression can be coerced tonumeric by subterfuges (kludges?) such as	expr + 0and to string by	expr ""(i.e., concatenation with a null string).4. Uninitialized variables have the numeric value0 and the string value "".  Accordingly, if x isuninitialized,	if (x) ...is false, and	if (!x) ...	if (x == 0) ...	if (x == "") ...are all true.  But note that	if (x == "0") ...is false.5. The type of a field is determined by contextwhen possible; for example,	$1++clearly implies that $1 is to be numeric, and	$1 = $1 "," $2implies that $1 and $2 are both to be strings.Coercion will be done as needed.In contexts where types cannot be reliably determined, e.g.,	if ($1 == $2) ...the type of each field is determined on input byinspection.  All fields are strings; in addition,each field that contains only a number (in thesense of Fortran, say) is also considered numeric.This ensures (for better or worse) that the test	if ($1 == $2) ...will succeed on the inputs	0	0.0	100	1e2	+100	100	1e-3	1e-3and fail on the inputs	(null)	0	(null)	0.0	2E-518	6E-427as we believe it should.Fields which are explicitly null have the stringvalue ""; they are not numeric.Non-existent fields (i.e., fields past NF) aretreated this way too.As it is for fields, so it is for array elementscreated by split(...).6. There is no warranty of merchantability nor any warrantyof fitness for a particular purpose nor any other warranty,either express or implied, as to the accuracy of theenclosed materials or as to their suitability for anyparticular purpose.  Accordingly, the AWK DevelopmentTask Force assumes no responsibility for their use by therecipient.   Further, the Task Force assumes no obligationto furnish any assistance of any kind whatsoever, or tofurnish any additional information or documentation.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?