Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: array bug



On Nov 13,  7:45pm, Dave Gaulke wrote:
} Subject: array bug
}
} function arrtest
} {
} 	set -A myarray
} 	typeset -x myarray
} 	myarray[1]=arrtest
} 	print ${myarray[1]}
} }
} 
} When I run this it prints only "a" and not the expected "arrtest".

This is not the bug you think it is.

"set -A myarray" is declaring a *global* (not local to "arrtest") array
named "myarray".  It's exactly equivalent to writing

	myarray=()

"typeset -x myarray" then declares a local scalar, also named "myarray",
which hides the global.  This is a result of a recent change that makes
"export" equivalent to "typeset -gx" and not equivalent to "typeset -x".
This is a known bug.  For the time being, you should use "export" when
you mean "export".

    function arrtest
    {
    	set -A myarray
	export myarray
	myarray[1]=arrtest
	print $myarray
    }

However, since arrays can't be exported in the first place (zsh marks
them exported internally, but does not put them in the environment) it's
almost certainly the case that you shouldn't have used "typeset -x" in
the first place.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author