From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10100 invoked by alias); 14 Jul 2013 13:36:43 -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: 17869 Received: (qmail 10156 invoked from network); 14 Jul 2013 13:36:28 -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 15:36:03 +0200 Message-ID: References: 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 * Mikael Magnusson (Sun, 14 Jul 2013 15:10:22 +0200) > On 14 July 2013 14:35, Thorsten Kampe wrote: > > Hi, > > > > I'd like to iterate over elements of an array. The elements are > > associative arrays. This is my code: > > > > """ > > #! /usr/bin/env zsh > > emulate -R zsh > > > > setopt nounset > > > > declare -A elem AssocArr1 AssocArr2 > > > > AssocArr1=(key value1) > > AssocArr2=(key value2) > > > > array=($AssocArr1 $AssocArr2) > > Do you really want these $ here? Yes, I really wanted to pass the actual associative arrays, but if I can pass the names that's fine with me, too. > You need to use the (P) flag to access a parameter indirectly. > % foo=(one two) > % bar=foo > % echo $bar[2] > o > % echo ${${bar}[2]} > o > % echo ${${(P)bar}[2]} > two Doesn't work for me: """ array=(AssocArr1 AssocArr2) for elem in $array do echo ${${(P)elem}[key]} done """ [empty output] Thorsten