[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] fatal: split: second argument is not an array
From: |
Aharon Robbins |
Subject: |
Re: [bug-gawk] fatal: split: second argument is not an array |
Date: |
Fri, 22 Mar 2013 10:21:56 +0200 |
User-agent: |
Heirloom mailx 12.5 6/20/10 |
Hi. Thanks for the note.
> Date: Thu, 21 Mar 2013 22:57:49 -0300
> From: Hermann Peifer <address@hidden>
> To: address@hidden
> Subject: [bug-gawk] fatal: split: second argument is not an array
>
> Hi,
>
> I tried to split fields 1, 2 and 3 into arrays a[1], a[2] and a[3]
> respectively, see the below example (1). I ended up with the
> above-mentioned fatal error and I wonder if the error is correct as the
> identifiers a[1], a[2] and a[3] have never been used before. So in my
> (potentially wrong) understanding, they are "untyped", which means they
> could be either used as a scalar variable or as an array.
I'm afraid you're misunderstanding. Any reference to a previously
non-existent element creates it *as a scalar* with an untyped value (which
acts as the null string or zero).
Consider:
BEGIN { printf("a[1] is <%s>\n", a[1]) }
a[1] is created and given an empty value, but it's a scalar value. This
is how awk has worked since The Beginning....
> I got around the fatal error by initialising a[1], a[2] and a[3] as
> arrays, see (2), but I wonder if this hack should really be necessary.
Yes, it is necessary.
Thanks,
Arnold