From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11844 invoked by alias); 14 Jul 2013 19:58:26 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17875 Received: (qmail 19397 invoked from network); 14 Jul 2013 19:58:21 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at m.gmane.org designates 80.91.229.3 as permitted sender) X-Injected-Via-Gmane: http://gmane.org/ To: zsh-users@zsh.org From: Thorsten Kampe Subject: Re: How to iterate over an array of associative arrays Date: Sun, 14 Jul 2013 21:57:52 +0200 Message-ID: References: <20130714182117.221d3501@pws-pc.ntlworld.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ip-62-143-201-36.unitymediagroup.de User-Agent: MicroPlanet-Gravity/3.0.4 * Peter Stephenson (Sun, 14 Jul 2013 18:21:17 +0100) > On Sun, 14 Jul 2013 15:36:03 +0200 > Thorsten Kampe 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 Looks good but as far as I can see it does not allow me to iterate over assiociative arrays so I can get the value of a certain key from all arrays. Say I have... AssocArr1=(key1 value11 key2 value12) AssocArr2=(key1 value21 key2 value22) So how do I iterate over... array=(AssocArr1 AssocArr2) ...so that I get value12 (= AssocArr1[key2]) in the first iteration and value22 (= AssocArr2[key2]) in the second? Thorsten