Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.awk > #9811
| From | porkchop@invalid.foo (Mike Sanders) |
|---|---|
| Newsgroups | comp.lang.awk |
| Subject | Re: {} Questions |
| Date | 2024-08-21 11:48 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <va4k6f$3rl80$1@dont-email.me> (permalink) |
| References | <va3ua5$3ohv3$2@dont-email.me> <87o75mpaec.fsf@bsb.me.uk> |
Ben Bacarisse <ben@bsb.me.uk> wrote:
> 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.
Thanks Ben.
>> 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.
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.
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...
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.
--
:wq
Mike Sanders
Back to comp.lang.awk | Previous | Next — Previous in thread | Next in thread | Find similar
{} Questions porkchop@invalid.foo (Mike Sanders) - 2024-08-21 05:35 +0000
Re: {} Questions Ben Bacarisse <ben@bsb.me.uk> - 2024-08-21 09:06 +0100
Re: {} Questions porkchop@invalid.foo (Mike Sanders) - 2024-08-21 11:48 +0000
Re: {} Questions Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-08-21 14:08 +0200
Re: {} Questions Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-08-21 14:10 +0200
Re: {} Questions porkchop@invalid.foo (Mike Sanders) - 2024-08-21 18:57 +0000
Re: {} Questions Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-08-22 00:51 +0200
Re: {} Questions Ben Bacarisse <ben@bsb.me.uk> - 2024-08-21 16:38 +0100
Re: {} Questions porkchop@invalid.foo (Mike Sanders) - 2024-08-21 19:01 +0000
csiph-web