-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nameref fails with nested associative arrays #594
Comments
Your local scoped map1 variable via
It is difficult at this time for ksh to arrive at your desired nested or multidimensional array structure by simply parsing your one liner nested compound assignment. ksh's default assignment for In this case as you have done in function func_a1 {
typeset -n ref=$1
typeset -A ref
ref[key1]=([key2]=val2)
}
$ func_b
Function a1: typeset -A map1=([key1]=([key2]=val2) )
Function a2: typeset -A map2=([key1]=([key2]=val2) )
$ typeset -p map1 map2
$ Or perhaps, we might set variable map1 to be an associate array from the start. function func_a1 {
typeset -n ref=$1
ref[key1]=([key2]=val2)
}
function func_b {
typeset -A map1
func_a1 map1
echo "Function a1: $(typeset -p map1)"
typeset map2
func_a2 map2
echo "Function a2: $(typeset -p map2)"
}
$ func_b
Function a1: typeset -A map1=([key1]=([key2]=val2) )
Function a2: typeset -A map2=([key1]=([key2]=val2) )
$ typeset -p map1 map2
$ See issue #148 for more insights. |
I have to say, it's quite frustrating when such important features are still unstable. |
I can understand your frustrations but I do not share your sentiment that ksh has important unstable features. Hopefully, as your proficiency with ksh continues to grow; your life will become easier and far less scary. From my viewpoint, most other command line scripting languages lack multidimensional array support so I consider ksh's array support as absolutely beneficial allowing me to program in a more concise and flexible manner than having to create workarounds with one-dimensional arrays only. |
This does look like a bug. The following version of the reproducer makes it slightly more obvious that the two functions should be equivalent: function func_a1 {
typeset -n ref=$1
typeset -A ref=(
[key1]=(
[key2]=val2
)
)
}
function func_a2 {
typeset -n ref=$1
typeset -A ref
ref[key1]=(
[key2]=val2
)
}
function func_b {
typeset map1
func_a1 map1
echo "Function a1: $(typeset -p map1)"
typeset map2
func_a2 map2
echo "Function a2: $(typeset -p map2)"
}
func_b Output:
Expected output:
|
Additional testing results based on new reproducer:
An example of pasted code change above:
|
Setting a nested associative arrays in one go fails on references:
The text was updated successfully, but these errors were encountered: