Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Janis Papanagnou Newsgroups: comp.lang.awk Subject: Re: Nitpicking the code (Was: Experiences with match() subexpressions?) Date: Mon, 14 Apr 2025 20:53:01 +0200 Organization: A noiseless patient Spider Lines: 42 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Mon, 14 Apr 2025 20:53:03 +0200 (CEST) Injection-Info: dont-email.me; posting-host="5f5bc6df05680b5fde3314ed5014a43e"; logging-data="2021727"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4eLHQyDS71j/IqpvaSIz8" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 Cancel-Lock: sha1:Tw1JIsjgf83M8yN0W5Oq2fhIn7c= In-Reply-To: Bytes: 2681 On 14.04.2025 20:20, Kenny McCormack wrote: > In article , > Ed Morton 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