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

    From Janis Papanagnou@21:1/5 to Kenny McCormack on Mon Apr 14 20:53:01 2025
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to mortonspam@gmail.com on Mon Apr 14 18:20:31 2025
    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.

    --
    "Only a genius could lose a billion dollars running a casino."
    "You know what they say: the house always loses."
    "When life gives you lemons, don't pay taxes."
    "Grab 'em by the p***y!"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Ed Morton on Tue Apr 15 05:35:14 2025
    On 15.04.2025 01:55, Ed Morton wrote:

    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.

    One nice property of Awk was that for decades its powerful features
    and its kernel functionality persisted and fancy features were not
    necessary to make good use of that tool.

    Janis


    Ed.


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)