bug-gawk
[Top][All Lists]
Advanced

[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: Mon, 17 Mar 2014 19:53:33 +0200
User-agent: Heirloom mailx 12.5 6/20/10

Hi.

> I am coming back to an older mail about arrays of arrays. At the time, 
> the issue was that I naively thought split("", a[1]) would force a[1] to 
> be an array, similar to split("", b), which does exactly this for b. 

Only if b was never used previously in the program.

> This is obviously not the case, as "Any reference to a previously 
> non-existent element creates it *as a scalar*".
>
> However: delete b[1] forces b[1] to be an array

No, it doesn't:

        $ cat foo.awk
        BEGIN {
                delete b[1]
                split ("", b[1])
        }
        $ gawk -f foo.awk      
        gawk: foo.awk:3: fatal: split: second argument is not an array

What it does do is totally remove the element "1" from b, allowing it to be
recreated later as an array:

        $ cat bar.awk
        BEGIN {
                b[1] = "scalar"
                delete b[1]
                b[1][2] = "a different scalar"
                print b[1][2]
        }
        $ gawk -f bar.awk 
        a different scalar

So, I don't think anything needs changing...

Thanks,

Arnold



reply via email to

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