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

Re: How to iterate over an array of associative arrays



On Sun, 14 Jul 2013 15:36:03 +0200
Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx> wrote:
> Yes, I really wanted to pass the actual associative arrays, but if I can 
> pass the names that's fine with me, too.

So maybe you're looking for:


typeset -A AssocArr1 AssocArr2
typeset -a array
typeset key value

AssocArr1=(key1 value1)
AssocArr2=(key2 value2)

# array is a normal array containing key/value pairs
array=(${(kv)AssocArr1} ${(kv)AssocArr2})

# scan array by pairs
for key value in $array
    do echo $key $value
done


?

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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