Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Copy assiociative arrays
On Mar 21, 10:28pm, Rene Neumann wrote:
}
} declare -A foo bar
} foo=(muh vier bla "\\sechs")
} bar=foo
That assignment converts bar into a scalar.
} # all output the empty string
} echo ${${(P)bar}[muh]}
An aside to explain this ...
${(P)bar} == ${foo} which is the array of values in the hash foo, in
no particular order. So it could be that ${${(P)bar}[2]} == "vier",
but the hash keys have been discarded by the time the subscript is
evaluated.
You can indirect into a hash like so:
bar='foo[muh]'
print ${(P)bar}
Unfortunately there's no subscript notation that returns both the key
and the value for an associative array element, and there's no way to
embed the (kv) expansion flag in the indirection. Zsh doesn't yet have
true "nameref" semantics like ksh.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author