[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Index function problem
From: |
Davide Brini |
Subject: |
Re: [bug-gawk] Index function problem |
Date: |
Sun, 21 Apr 2013 18:50:25 +0200 |
On Sun, 21 Apr 2013 18:02:10 +0200, Davide Brini <address@hidden> wrote:
> On Sun, 21 Apr 2013 08:06:33 +0100, Christopher Durant
> <address@hidden> wrote:
>
> > I notice that if you use a regular expression as the second parameter in
> > an index call e.g. index ($0, /[A-Z]/); it is allowed but gives
> > unpredictable results. Perhaps this usage should be flagged as an
> > error.
>
> awk converts /[A-Z]/ into 1 or 0 depending on whether $0 matches the
> pattern. This number is then converted into a string, which is what
> index() expect.
>
> See these examples:
>
> # this is like doing index($0, "0")
> $ echo 'aBCD' | awk '{ print index($0, /[A-Z]/) }'
> 0
The comment above had to be, of course, the same as the second example,
that is:
# this is like doing index($0, "1")
--
D.