Groups | Search | Server Info | Login | Register


Groups > comp.lang.awk > #9950

Re: Nitpicking the code (Was: Experiences with match() subexpressions?)

From Ed Morton <mortonspam@gmail.com>
Newsgroups comp.lang.awk
Subject Re: Nitpicking the code (Was: Experiences with match() subexpressions?)
Date 2025-04-14 18:55 -0500
Organization A noiseless patient Spider
Message-ID <vtk799$2dego$1@dont-email.me> (permalink)
References (1 earlier) <vt7qs4$2gior$1@dont-email.me> <vt9q0n$70fm$1@dont-email.me> <vtgtkr$3br8e$1@dont-email.me> <vtjjlf$1ni8g$1@news.xmission.com> <vtjlif$1tmav$1@dont-email.me>

Show all headers | View raw


On 4/14/2025 1:53 PM, Janis Papanagnou wrote:
> On 14.04.2025 20:20, Kenny McCormack wrote:
>> In article <vtgtkr$3br8e$1@dont-email.me>,
>> Ed Morton  <mortonspam@gmail.com> wrote:
>> ...
>>>      data = "R=\"R=r1,R=r2\",R=r2,R=r3,E=e"
>>>      nf = patsplit(data, arr, /[RE]=([^,]*|"([^"]|"")*")/)
>>>      delete arr
>>>      for ( i in arr ) {
>>>          sub(/[^=]+=/, "", arr[i])
>>>      }
>>
>> This can't be right, since if the sequence:
>>      delete arr
>>      for (i in arr) ...
>> can't possibly do anything.  I.e., the for statement will be a no-op, since
>> the array is empty at that point.

Yeah, remove that `delete arr`, it's not necessary since `patsplit()` 
will delete `arr` before populating it and `delete arr` in that location 
would break the code.

>>
>>> or any awk:
>>>
>>>      data = "R=\"R=r1,R=r2\",R=r2,R=r3,E=e"
>>>      nf = 0
>>>      delete arr
>>>      while ( match(data, /[RE]=([^,]*|"([^"]|"")*")/, a) ) {
>>>          arr[++nf] = substr(data, RSTART+2, RLENGTH-2)
>>>          data = substr(data, RSTART+RLENGTH)
>>>      }
>>
>> I believe "delete arr" (without an index, hence removing the entire array)
>> is an "extension".  I can't quite quote chapter and verse, but I note that
>> "man mawk" explicitly mentions that mawk supports this syntax, thereby
>> implying that it isn't "standard".  Of course, gawk supports it as well.

`delete arr` is defined by the current POSIX standard 
(https://pubs.opengroup.org/onlinepubs/9799919799/utilities/awk.html) as 
equivalent to `for (index in array) delete array[index]` but for years 
prior to that [almost?] every maintained awk supported `delete arr` anyway.


>> So, if by "any awk", you mean "strictly standard", then, well, you can see
>> where I am going with this.
> 
> I seem to recall that a standard way to clear an array could be using
>    split("", arr)

`split("", arr)` was the defacto "standard" way to delete an array's 
content without looping before `delete arr` was adopted by POSIX. In all 
seriousness if anyone is using an awk that doesn't support `delete arr` 
then they need to get a new awk as who knows what other features it 
might be lacking.

	Ed.

> for example. To my taste it looks a bit clumsy, not as nice as using
> 'delete', but well, whatever one prefers.
> 
> Janis
> 

Back to comp.lang.awk | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Experiences with match() subexpressions? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-04-10 09:06 +0200
  Re: Experiences with match() subexpressions? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-04-10 09:09 +0200
    Re: Experiences with match() subexpressions? gazelle@shell.xmission.com (Kenny McCormack) - 2025-04-10 11:08 +0000
      Re: Experiences with match() subexpressions? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-04-10 13:55 +0200
        Re: Experiences with match() subexpressions? gazelle@shell.xmission.com (Kenny McCormack) - 2025-04-10 14:04 +0000
          Re: Experiences with match() subexpressions? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-04-10 23:39 +0200
            Re: Experiences with match() subexpressions? arnold@freefriends.org (Aharon Robbins) - 2025-04-11 06:33 +0000
              Re: Experiences with match() subexpressions? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-04-11 09:10 +0200
                Re: Experiences with match() subexpressions? Kaz Kylheku <643-408-1753@kylheku.com> - 2025-04-11 08:22 +0000
                Re: Experiences with match() subexpressions? Manuel Collado <mcollado2011@gmail.com> - 2025-04-18 12:03 +0200
                Re: Experiences with match() subexpressions? gazelle@shell.xmission.com (Kenny McCormack) - 2025-04-18 12:01 +0000
                Re: Experiences with match() subexpressions? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-04-18 14:24 +0200
              Re: Experiences with match() subexpressions? Kaz Kylheku <643-408-1753@kylheku.com> - 2025-04-11 07:40 +0000
              The new matcher (Was: Experiences with match() subexpressions?) gazelle@shell.xmission.com (Kenny McCormack) - 2025-04-11 08:57 +0000
                Re: The new matcher (Was: Experiences with match() subexpressions?) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-04-11 15:50 +0200
              Re: Experiences with match() subexpressions? Kaz Kylheku <643-408-1753@kylheku.com> - 2025-04-11 17:54 +0000
    Re: Experiences with match() subexpressions? Ed Morton <mortonspam@gmail.com> - 2025-04-10 20:07 -0500
      Re: Experiences with match() subexpressions? Ed Morton <mortonspam@gmail.com> - 2025-04-13 12:52 -0500
        Nitpicking the code (Was: Experiences with match() subexpressions?) gazelle@shell.xmission.com (Kenny McCormack) - 2025-04-14 18:20 +0000
          Re: Nitpicking the code (Was: Experiences with match() subexpressions?) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-04-14 20:53 +0200
            Re: Nitpicking the code (Was: Experiences with match() subexpressions?) Ed Morton <mortonspam@gmail.com> - 2025-04-14 18:55 -0500
              Re: Nitpicking the code (Was: Experiences with match() subexpressions?) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-04-15 05:35 +0200

csiph-web