Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Possible error in GAWK's join.awk sample script?

28 views
Skip to first unread message

Kenny McCormack

unread,
Oct 17, 2016, 7:19:12 AM10/17/16
to
Here's the script, apparently unchanged for 23 years:


--- Cut Here ---
# join.awk --- join an array into a string
#
# Arnold Robbins, arn...@skeeve.com, Public Domain
# May 1993

function join(array, start, end, sep, result, i)
{
if (sep == "")
sep = " "
else if (sep == SUBSEP) # magic value
sep = ""
result = array[start]
for (i = start + 1; i <= end; i++)
result = result sep array[i]
return result
}
--- Cut Here ---

Observe that if end is less than start, the return value is array[start],
when it probably should be an empty string.

E.g.,

print join(A,3,2,",")

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain in
compliance with said RFCs, the actual sig can be found at the following web address:
http://www.xmission.com/~gazelle/Sigs/Seneca

Kenny McCormack

unread,
Oct 17, 2016, 7:47:36 AM10/17/16
to
In article <nu2c3e$3ha$1...@news.xmission.com>,
Kenny McCormack <gaz...@shell.xmission.com> wrote:
...
>Observe that if end is less than start, the return value is array[start],
>when it probably should be an empty string.

And while we're on the subject, note also that if end is greater than the
number of elements in the array, you'll get output with trailing sep
characters. Something like:

val1,val2,val3,,,,,

Whether this is desirable or not is something upon which reasoned men may
disagree.

--
To most Christians, the Bible is like a software license. Nobody
actually reads it. They just scroll to the bottom and click "I agree."

- author unknown -
0 new messages