[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: the wonder of "cannot assign to arbitrary elements"
From: |
arnold |
Subject: |
Re: the wonder of "cannot assign to arbitrary elements" |
Date: |
Mon, 13 Dec 2021 00:20:56 -0700 |
User-agent: |
Heirloom mailx 12.5 7/5/10 |
Manuel's answer is correct.
Denis,
Please see the updated discussion for bug reporting and asking questions about
gawk, starting at https://www.gnu.org/software/gawk/manual/html_node/Bugs.html.
Please read ALL the subsections there.
In particular, please note that questions such as these should now be sent to
the
help-gawk@gnu.org mailing list, reserving the bug list ONLY for bug reports.
Thanks,
Arnold
Manuel Collado <mcollado2011@gmail.com> wrote:
> El 12/12/2021 a las 19:52, Denis Shirokov escribió:
> > BEGIN{
> > typeof( a )
> > SYMTAB[ "a" ] = 1
> > SYMTAB[ "b" ] = 2 # <- here will
> > be an arbitrary element erro
> > }
>
> This is on purpose.
>
> >
> > could someone please inform me what's the difference between a and b ?
> > and how to avoid an error with 'a' ?
> ------------------------------->-'b', I suppose.
>
> Variables are created when the awk script is parsed, not when it is
> executed. "a" is the name of a variable, and hence there is a
> corresponding SYMTAB entry.
>
> "b" is just an invalid index of SYMTAB. Invalid because there is no
> variable with such name.
>
> >
> > feature of accessing the content of the global variables for writes is
> > useless.
>
> You can *assign* values to variables via SYMTAB, but you can not use
> SYMTAB to *create* variables. To create a variable, just mention it in
> the script code.
>
> gawk '
> BEGIN{
> typeof( a )
> b
> SYMTAB[ "a" ] = 1
> SYMTAB[ "b" ] = 2 # <- No error here.
> print b
> }'
>
> 2
>
> Works as expected.
>
> >
> >
> > commonly - the fatal "cannot assign to arbitrary elements" - is idea that's
> > does more harm than good. it's practically nullifies feature of write
> > access to the content
> > of global variables because it is better to perform direct value
> > writing instead of trying
> > to understand why(and where) gawk determinates an element as an
> > arbitrary element of SYMTAB.
> >
> > as a gawk user i may say that without fatal "cannot assign to
> > arbitrary elements" - life was been really easier and nice
> > and gawk was been more flexible.
>
> It was in the past. But with a different, confusing semantics. So
> arbitrary SYMTAB indexes were finally forbidden.
>
> >
> > Kind Regrads
> > Denis
>
> HTH. Regards.
>
> --
> Manuel Collado - http://mcollado.z15.es