bug-gawk
[Top][All Lists]
Advanced

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

Re: typeof() creates elements in an array


From: arnold
Subject: Re: typeof() creates elements in an array
Date: Wed, 29 Sep 2021 00:31:26 -0600
User-agent: Heirloom mailx 12.5 7/5/10

"Andrew J. Schorr" <aschorr@telemetry-investments.com> wrote:

> Here's what looks like a more interesting question to me regarding
> this issue.
>
> bash-4.2$ ./gawk 'BEGIN {print typeof(x); x[0] = 0; print typeof(x)}'
> untyped
> array
>
> bash-4.2$ ./gawk 'BEGIN {print typeof(x[0]); x[0][0] = 0; print typeof(x[0])}'
> unassigned
> gawk: cmd. line:1: fatal: attempt to use scalar `x["0"]' as an array
>
> This example does seem to be more at odds with the language in the manual,

Which language in the manual, please?

> since the array element here has been created as a unassigned scalar, not
> as an untyped value. I don't know whether that can be avoided. The array
> instantiation stuff is tricky.

It can't be avoided. This is a backwards compatibility issue. In
standard awk:

        BEGIN {
                print length(x[0])
        }

creates x[0] as unassigned scalar.  Gawk can't do anything different
from this.  If you want a multidimensional array, you have to
create it that way to start with.

Thanks,

Arnold



reply via email to

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