[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug adding K,V pairs to existing hash with HASH+=([K]=V)
From: |
Dan Douglas |
Subject: |
Re: bug adding K,V pairs to existing hash with HASH+=([K]=V) |
Date: |
Tue, 16 Feb 2016 01:06:49 -0600 |
Ah so `arr+=([a]=x [b]=y)` will no longer be the same as `arr+=([a]+=x
[b]+=y)`? I never liked that for associative arrays because the only
workaround was to do multiple arr[key]= assignments to update or add
more than one element at a time.
My thinking was that this is due to bash's unique auto-incrementing of
indexed array keys. Since in ksh you're not allowed to specify an
index for one element of a compound assignment without specifying it
for all elements, bash has some additional things to consider.
~ $ bash-4.2 -c 'typeset -ia a=({0..5}); a+=([0]+=1 {2..4}); typeset -p a'
declare -ai a='([0]="1" [1]="3" [2]="5" [3]="7" [4]="4" [5]="5")'
Bash 4.4:
~ $ ./doc/programs/bash-build/bash -c 'typeset -ia a=({0..5});
a+=([0]+=1 {2..4}); typeset -p a'
declare -ai a=([0]="1" [1]="2" [2]="3" [3]="4" [4]="4" [5]="5")
I almost think it makes sense to treat ordered and unordered
collections differently. With an unordered collection an outer +=
should obviously mean "add or update for each assignment". For an
ordered collection when appending beginning at an index lower than the
max index I'm not so sure.
--
Dan Douglas
- bug adding K,V pairs to existing hash with HASH+=([K]=V), Linda Walsh, 2016/02/15
- Re: bug adding K,V pairs to existing hash with HASH+=([K]=V), Chet Ramey, 2016/02/15
- Re: bug adding K,V pairs to existing hash with HASH+=([K]=V), Linda Walsh, 2016/02/15
- Re: bug adding K,V pairs to existing hash with HASH+=([K]=V), Chet Ramey, 2016/02/15
- Re: bug adding K,V pairs to existing hash with HASH+=([K]=V),
Dan Douglas <=
- Re: bug adding K,V pairs to existing hash with HASH+=([K]=V), Linda Walsh, 2016/02/16
- Re: bug adding K,V pairs to existing hash with HASH+=([K]=V), Dan Douglas, 2016/02/16
- Re: bug adding K,V pairs to existing hash with HASH+=([K]=V), Dan Douglas, 2016/02/16
- Re: bug adding K,V pairs to existing hash with HASH+=([K]=V), Greg Wooledge, 2016/02/16
- Re: bug adding K,V pairs to existing hash with HASH+=([K]=V), Chet Ramey, 2016/02/16