|
From: | Ed Morton |
Subject: | Re: attribution of ++ to the wrong variable in "a ++b" |
Date: | Tue, 13 Sep 2022 06:40:47 -0500 |
User-agent: | Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 |
On 9/13/2022 5:42 AM, Pascal Maugis wrote:
Hi, as promised here is the strange, unexpected behavior of ++ that looks like an error to me, because in "a ++b", a is incremented instead of b. "a b++" and "a++ b" produce the correct results however :Pascal - with a few exceptions, white space generally doesn't matter to awk. If you want to ensure that `a ++b` gets interpreted as `a (++b)` then that latter is the code you need to write since once you remove/ignore white space `a++ b` and `a ++b` are both `a++b` which visually could be interpreted either way.touch a.awk gawk -D -f ./a.awk eval "a=1 ; b=2" eval "print a ++b" ; output = 12 : (variables will be incremented after the operation, ok with me as documented)eval "print a b" ; output = 22 : a has been incremented instead of beval "print a++b" ; output = 22 : eval "print a b" ; output = 32 : a has been incrementedThe operation seems to be interpreted as "a++b", the space been uninterpreted as a separator
Ed.
[Prev in Thread] | Current Thread | [Next in Thread] |