Re: {} Questions

Liste des GroupesRevenir à cl awk 
Sujet : Re: {} Questions
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.awk
Date : 21. Aug 2024, 13:08:08
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <va4lb8$3rq72$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
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.
 


Date Sujet#  Auteur
21 Aug 24 * {} Questions9Mike Sanders
21 Aug 24 `* Re: {} Questions8Ben Bacarisse
21 Aug 24  `* Re: {} Questions7Mike Sanders
21 Aug 24   +* Re: {} Questions4Janis Papanagnou
21 Aug 24   i+- Re: {} Questions1Janis Papanagnou
21 Aug 24   i`* Re: {} Questions2Mike Sanders
22 Aug 24   i `- Re: {} Questions1Janis Papanagnou
21 Aug 24   `* Re: {} Questions2Ben Bacarisse
21 Aug 24    `- Re: {} Questions1Mike Sanders

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal