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

Liste des GroupesRevenir à cl awk 
Sujet : Re: Nitpicking the code (Was: Experiences with match() subexpressions?)
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.awk
Date : 14. Apr 2025, 19:53:01
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vtjlif$1tmav$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
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.
 
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.
 
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)
for example. To my taste it looks a bit clumsy, not as nice as using
'delete', but well, whatever one prefers.

Janis


Date Sujet#  Auteur
10 Apr 25 * Experiences with match() subexpressions?22Janis Papanagnou
10 Apr 25 `* Re: Experiences with match() subexpressions?21Janis Papanagnou
10 Apr 25  +* Re: Experiences with match() subexpressions?14Kenny McCormack
10 Apr 25  i`* Re: Experiences with match() subexpressions?13Janis Papanagnou
10 Apr 25  i `* Re: Experiences with match() subexpressions?12Kenny McCormack
10 Apr 25  i  `* Re: Experiences with match() subexpressions?11Janis Papanagnou
11 Apr 25  i   `* Re: Experiences with match() subexpressions?10Aharon Robbins
11 Apr 25  i    +* Re: Experiences with match() subexpressions?5Janis Papanagnou
11 Apr 25  i    i+- Re: Experiences with match() subexpressions?1Kaz Kylheku
18 Apr 25  i    i`* Re: Experiences with match() subexpressions?3Manuel Collado
18 Apr 25  i    i +- Re: Experiences with match() subexpressions?1Kenny McCormack
18 Apr 25  i    i `- Re: Experiences with match() subexpressions?1Janis Papanagnou
11 Apr 25  i    +- Re: Experiences with match() subexpressions?1Kaz Kylheku
11 Apr 25  i    +* The new matcher (Was: Experiences with match() subexpressions?)2Kenny McCormack
11 Apr 25  i    i`- Re: The new matcher (Was: Experiences with match() subexpressions?)1Janis Papanagnou
11 Apr 25  i    `- Re: Experiences with match() subexpressions?1Kaz Kylheku
11 Apr 25  `* Re: Experiences with match() subexpressions?6Ed Morton
13 Apr 25   `* Re: Experiences with match() subexpressions?5Ed Morton
14 Apr 25    `* Nitpicking the code (Was: Experiences with match() subexpressions?)4Kenny McCormack
14 Apr 25     `* Re: Nitpicking the code (Was: Experiences with match() subexpressions?)3Janis Papanagnou
15 Apr 25      `* Re: Nitpicking the code (Was: Experiences with match() subexpressions?)2Ed Morton
15 Apr 25       `- Re: Nitpicking the code (Was: Experiences with match() subexpressions?)1Janis Papanagnou

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal