zsh-users
 help / color / mirror / code / Atom feed
* Copy assiociative arrays
@ 2012-03-21 21:28 René Neumann
  2012-03-21 21:44 ` Mikael Magnusson
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: René Neumann @ 2012-03-21 21:28 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 761 bytes --]

Hi all,

is it possible to copy associative arrays?

I.e. have

declare -A foo bar
foo=(muh vier bla "\\sechs")
bar=$foo

using this, bar only contains the values of foo (and using ${(kv)foo}
instead still only makes it a string).

The current awkward way I found is:

declare -A foo bar
foo=(muh vier bla "\\sechs")
: ${(AA)bar::=${(kv)foo}}

But this seems rather cluttered and unintuitive...

The other way is using indirection, in that bar only holds the string
"foo" and with the (P) flag this is resolved. But unfortunately I can't
make it work with subscripts:

declare -A foo bar
foo=(muh vier bla "\\sechs")
bar=foo
# all output the empty string
echo ${${(P)bar}[muh]}
echo ${${bar}[muh]}

Thanks and regards,
René


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-03-21 22:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-21 21:28 Copy assiociative arrays René Neumann
2012-03-21 21:44 ` Mikael Magnusson
2012-03-21 21:46 ` Moritz Bunkus
2012-03-21 22:08   ` René Neumann
2012-03-21 22:15     ` Frank Terbeck
2012-03-21 22:38 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).