help-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Awk output redirection to expression - defined or not?


From: Manuel Collado
Subject: Re: Awk output redirection to expression - defined or not?
Date: Fri, 26 May 2023 10:24:01 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0

El 25/5/23 a las 15:37, Ed Morton escribió:
[...]
Historical practice has been that:
getline < "a" "b"

is parsed as:

( getline < "a" ) "b"

although many would argue that the intent was that the file *ab* should be read. However:

getline < "x" + 1

parses as:

getline < ( "x" + 1 )

...

Since in most cases such constructs are not (or at least should not) be used (because they have a natural ambiguity for which there is no conventional parsing), the meaning of these constructs has been made explicitly unspecified.

and:

The *getline* operator can form ambiguous constructs when there are unparenthesized binary operators (including concatenate) to the right of the '<' (up to the end of the expression containing the *getline*). The result of evaluating such a construct is unspecified

but nothing about output redirection. I know gawk doesn't require parens around the expression for output redirection but other awks do (e.g. see https://stackoverflow.com/q/21093626/1745001) and it's not obvious to me why `getline < "a" "b"` should be undefined behavior while `print > "a" "b"` wouldn't be so intuitively if one of them is undefined then so should the other be.

Well, there is a clear difference. 'getline' is an expression term, while 'print' is a statement. IMHO, in the first case the '<' appears as an operator, parsed according to operator precedence ('<' after getline has higher precedence than '<' as comparison operator). In the second case '>' is parsed as a keyword.

HTH.
--
Manuel Collado - http://mcollado.z15.es



reply via email to

[Prev in Thread] Current Thread [Next in Thread]