Re: Experiences with match() subexpressions?

Liste des GroupesRevenir à cl awk 
Sujet : Re: Experiences with match() subexpressions?
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.lang.awk
Date : 10. Apr 2025, 15:04:46
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vt8j5u$1gmdg$1@news.xmission.com>
References : 1 2 3 4
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <vt8bit$2uiq5$1@dont-email.me>,
Janis Papanagnou  <janis_papanagnou+ng@hotmail.com> wrote:
...
I have to admit that I (still) don't really understand how this match third
arg stuff works.
...
I.e., I can never predict what will happen, so I always
just dump out the array and try to reverse-engineer it each time I need to
use it.
...
Above output stuff appears because in 'arr' there's additional elements
about the pattern positions stored.

Just to clarify, I wasn't looking for a tutorial (man page regurgitation).
I understand the man page description of match's 3rd arg as well as anyone;
I just find it that it doesn't do as much in practice as (I think) it
should - and that it is unpredictable (by me, anyway) what it will do (you
have to dump out the array and trial-and-error it to get it to do what you
want).  It promises more than it delivers.  I have much the same comments
to make about the similar functionality in Tcl (Expect).

None of which is criticism of the feature; as you say below, it basically
does as much as the underlying regexp library allows it to do.

...
I think I'll do the parsing the straightforward two-step way as I did
before the GNU Awk specific functions were available; it's probably
also the clearest way to program that functionality.

Probably so.  BTW, it is not really "GNU Awk specific"; lots of languages
have this general capability.

Incidentally, here is a function of mine that uses match's 3rd arg.  I find
it useful.  This addresses a common AWK issue, where you have a line with
fields (in the usual AWK whitespace-delimited sense), but you need to know
the actual character positions of the fields (since they can move around
from line to line of input).  Note also that I'm not really sure where the
name "splitMatch" came from; it was just what popped into my head when I
was writing this...

--- Cut Here ---
# Find the character positions of each of the fields in string s.
# Note that s will usually be $0, and n will usually be NF.
function splitMatch(s,n,A, i,t) {
    for (i=1; i<=n; i++) t = t "([^ \t]+)[ \t]*"
    return match(s,t,A)
    }
--- Cut Here ---

--
In the corner of the room on the ceiling is a large vampire bat who
is obviously deranged and holding his nose.

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