bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Why the length(seps) is one more than the return value of


From: Manuel Collado
Subject: Re: [bug-gawk] Why the length(seps) is one more than the return value of patsplit()?
Date: Sun, 08 Mar 2015 14:08:56 +0100
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.1

El 08/03/2015 13:36, address@hidden escribió:
Peng Yu <address@hidden> wrote:

The following code shows that the length(seps) is one more than the
return value of patsplit(). I thought that seps should have the same
as the number of elements in "a". Why it is not the case? Could
anybody help me understand this? Thanks.

~$ awk 'BEGIN { print patsplit("aAbBcC", a, /[a-z]/, seps); print
seps[1], seps[2], seps[3], length(seps); }'
3
A B C 4

Hi. Thanks for the report.  The fourth element is the null string. This
may be a bug. I need to review the code and work with it a bit.  I'll
reply again when I have more information.

IIRC, this was already discussed more than a year ago.

A record with N fields has N+1 potential separators, because there can be non null separators at both the begin and end of the record. At least for the default (space) separator.

Or perhaps it is the opposite: N separators may delimit N+1 fields.

Regards.
--
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado




reply via email to

[Prev in Thread] Current Thread [Next in Thread]