[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: delete of nested array is in consistent
From: |
arnold |
Subject: |
Re: delete of nested array is in consistent |
Date: |
Fri, 17 Apr 2020 07:46:32 -0600 |
User-agent: |
Heirloom mailx 12.5 7/5/10 |
I poked at this in a debugger. Basically for
BEGIN { delete a[1][""]; print typeof(a[1]) }
a[1] never existed as a defined array, just as a[1][""] doesn't have any
value associated with it. Thus the delete effectively does nothing.
So, when typeof() is called on a[1], it reports undefined, since no direct
assignment was ever made to it.
Andy's suggestion:
BEGIN { a[1][""]; delete a[1][""]; print typeof(a[1]) }
is the right way to go to force gawk to create a[1] and make it
into an array.
Forcing that creation from within the delete statement is way too
hard to do, and definitely much less clear at the awk level as to
what's going on anyway.
Arnold
"Andrew J. Schorr" <address@hidden> wrote:
> On Fri, Apr 17, 2020 at 01:26:17AM -0600, address@hidden wrote:
> > Peng Yu <address@hidden> wrote:
> >
> > > See below. I'd expect the second one should also print array. Is it a bug?
> > >
> > > $ awk -e 'BEGIN { delete a[""]; print typeof(a) }'
> > > array
> > > $ awk -e 'BEGIN { delete a[1][""]; print typeof(a[1]) }'
> > > unassigned
> > >
> > > --
> > > Regards,
> > > Peng
> >
> > Upgrade your version of gawk:
> >
> > $ ./gawk --version | sed 2q
> > GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.0.1, GNU MP 6.1.2)
> > Copyright (C) 1989, 1991-2020 Free Software Foundation.
> > $ ./gawk 'BEGIN { delete a[""]; print typeof(a) }'
> > array
> > $ ./gawk 'BEGIN { delete a[1][""]; print typeof(a) }'
> > array
>
> Actually, in latest gawk, his second example still says unassigned:
>
> bash-4.2$ ./gawk --version | head -1
> GNU Awk 5.1.0, API: 3.0 (GNU MPFR 3.1.1, GNU MP 6.0.0)
> bash-4.2$ ./gawk 'BEGIN { delete a[1][""]; print typeof(a[1]) }'
> unassigned
>
> This gives the desired outcome:
> bash-4.2$ ./gawk 'BEGIN { a[1][""]; delete a[1][""]; print typeof(a[1]) }'
> array
>
> Regards,
> Andy
- delete of nested array is in consistent, Peng Yu, 2020/04/16
- Re: delete of nested array is in consistent, david kerns, 2020/04/16
- Re: delete of nested array is in consistent, arnold, 2020/04/17
- Re: delete of nested array is in consistent, Andrew J. Schorr, 2020/04/17
- Re: delete of nested array is in consistent,
arnold <=
- Re: delete of nested array is in consistent, Peng Yu, 2020/04/17
- Re: delete of nested array is in consistent, arnold, 2020/04/20
- Re: delete of nested array is in consistent, Denis Shirokov, 2020/04/23
- Re: delete of nested array is in consistent, Peng Yu, 2020/04/26
- Re: delete of nested array is in consistent, david kerns, 2020/04/26
- Re: delete of nested array is in consistent, arnold, 2020/04/27