Deutsch English Français Italiano |
<va4lb8$3rq72$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com> Newsgroups: comp.lang.awk Subject: Re: {} Questions Date: Wed, 21 Aug 2024 14:08:08 +0200 Organization: A noiseless patient Spider Lines: 60 Message-ID: <va4lb8$3rq72$1@dont-email.me> References: <va3ua5$3ohv3$2@dont-email.me> <87o75mpaec.fsf@bsb.me.uk> <va4k6f$3rl80$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Wed, 21 Aug 2024 14:08:08 +0200 (CEST) Injection-Info: dont-email.me; posting-host="82e07ed007e815afc5a870beac446b47"; logging-data="4057314"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19rxzBVHGiuXSoKJQqPq+fX" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 Cancel-Lock: sha1:qOpf7v2639YDNrDwOO7ZTw1/8wg= In-Reply-To: <va4k6f$3rl80$1@dont-email.me> X-Enigmail-Draft-Status: N1110 Bytes: 2877 On 21.08.2024 13:48, Mike Sanders wrote: > [ Concerning the basic awk syntax: condition { action } ] > And yet there's still more implied nuance somehow. Let me try to articulate > my thoughts... > > - These types of constructs are 'auto' ran per line of input (assuming > its not located within another user-written function) that I get. You cannot have these constructs with their given semantics inside a function. You'd have to formulate them explicitly (in the imperative form) with 'if', as in function f () { if (condition) action } > Perhaps a potential efficiency hit to be aware of. > > - There's also the scope of variables to consider... Because any > variable's located outside of a user-written function or conversely > located within a 'bare naked' construct is global, or at least > exposed to the entire script's 'world', so I want be careful here... All variables have global scope, with the exception of those specified in a function argument list along with the real arguments, as in function f (arg1, arg2, local1, local2) { global = arg1 ; ... } f ("Hello", 42); (There's some caveat with arrays in the function argument list.) Janis > > I'm guessing that any construct that lacks a function signature > is globally scoped: > > { im_global = 42 } > > while those with a function signature (located within parentheses) > are locally scoped: > > function private(private_var1) { private_var1 = "foo" } > > - And 2 more... > > $ awk '{ v="im_global" }' > > $ awk -f foo -v global=55 > > Anything within the above 2 are global as well? > > Just thinking aloud here so, I'll let you long time posters describe > it more lucidly. >