bug-gawk
[Top][All Lists]
Advanced

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

Re: attribution of ++ to the wrong variable in "a ++b"


From: arnold
Subject: Re: attribution of ++ to the wrong variable in "a ++b"
Date: Tue, 13 Sep 2022 07:07:28 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Awk doesn't care (much) about spaces because of string concatenation:

        a = "hello "
        b = "world"
        print a b

Arnold

Pascal Maugis <pascal.maugis@lsce.ipsl.fr> wrote:

> Thanks Ed,
>
> I didn't know that awk cared little for spaces as separators. I will 
> switch to parenthesis, then.
>
> May I suggest this aspect be stressed somewhere in the documentation, 
> maybe after §1.6, or §6.2 Operators: Doing Something with Values, or 
> specifically for ++ in §6.2.4. ?
>
> Cheers,
>
> Pascal.
>
> Le 13/09/2022 à 13:40, Ed Morton a écrit :
> > 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 :
> >>
> >>    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 b
> >>    eval "print a++b"    ; output = 22 :
> >>    eval "print a b"     ; output = 32 : a has been incremented
> >>
> >> The operation seems to be interpreted as "a++b", the space been 
> >> uninterpreted as a separator
> >>
> > 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.
> >
> >     Ed.
> -- 
> ------------------------------------------------------------------------
>
> *Pascal MAUGIS*
> Modélisation hydrologique et changement climatique, PhD
>
> LSCE
>
> Laboratoire des Sciences du Climat et de l'Environnement 
> <http://www.lsce.ipsl.fr/>
>
> Unité Mixte de Recherche CEA-CNRS-UVSQ (UMR 8212), IPSL, Paris-Saclay
> Equipe MOSAIC : MOdelisation des SurfAces et Interfaces Continentales
> Bât. 714, pièce 2115
> C.E. Saclay, Orme des Merisiers, 91191 Gif-sur-Yvette Cedex, FRANCE
>
> e-mail : pascal.maugis@lsce.ipsl.fr
> Page perso : FR <http://www.lsce.ipsl.fr/Pisp/pascal.maugis/> - EN 
> <http://www.lsce.ipsl.fr/en/Phocea/Pisp/index.php?nom=pascal.maugis>
> Tel./Fax : +33 1 69 08 75 24 / +33 1 69 08 77 16
>
> ------------------------------------------------------------------------



reply via email to

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