Sujet : Re: {} Questions
De : ben (at) *nospam* bsb.me.uk (Ben Bacarisse)
Groupes : comp.lang.awkDate : 21. Aug 2024, 09:06:51
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <87o75mpaec.fsf@bsb.me.uk>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13)
porkchop@invalid.foo (Mike Sanders) writes:
Assuming any awk variant...
>
1. Is this valid? (it works with mawk, gawk, busy box awk)
>
BEGIN { debug = 1 }
>
(debug) { code_here }
>
(!debug) { code_here }
>
END { ... }
Yes, that's valid. You don't need the ()s round the expressions.
2. what is the name or accepted term in AWK for unamed functions,
main()?
I don't know what you mean. Can you give an example?
It occurs to me that maybe you think
(debug) { code }
is a function? It's not. It's just a normal pattern/action AWK pair.
An AWK pattern can just be an expression. That expression is evaluated
for every input line and, if true, the corresponding action is executed.
You could have written
debug != 0 { code }
instead.
-- Ben.