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

Re: uninvited members of associative array



Lawrence Velázquez wrote on Sat, Dec 17, 2022 at 16:07:50 -0500:
> Bart already addressed the actual issue, so I'll just touch on this:
> 
> On Sat, Dec 17, 2022, at 3:31 PM, Ray Andrews wrote:
> > I don't understand 
> > the difference between '-A' and '+A' maybe that's part of it -- the 
> > global array might not be overwritten cleanly or something.
> 
> If the array is already populated, "set +A" only replaces its leading
> elements, which means existing elements can get left behind.
> 
> 	% arr=({a..j}); typeset -p arr
> 	typeset -a arr=( a b c d e f g h i j )
> 	% set -A arr {1..5}; typeset -p arr
> 	typeset -a arr=( 1 2 3 4 5 )
> 	% set +A arr x y z; typeset -p arr
> 	typeset -a arr=( x y z 4 5 )
> 
> I'm not sure why you brought this up.  Are you using "set +A"
> somewhere?

Could someone please clarify this in the manual?  zshbuiltins(1) says
"will replace the initial elements of the array" and it's not clear that
"initial elements" doesn't mean "all elements" but only the prefix ones.

Thanks,

Daniel




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