Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: How to iterate over an array of associative arrays
- X-seq: zsh-users 17868
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx>
- Subject: Re: How to iterate over an array of associative arrays
- Date: Sun, 14 Jul 2013 15:10:22 +0200
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=d8MawtpcdoF4ncyFngbIb9ZCMx56Y6auXVDVi51oLbU=; b=yEhp5GNiOgY+DNGShOGhha0fAndhX+SuujUmPvXfU2jq774JA0D7wZHWQXTbUxA/ss uhOuQPeUUkbljJjVLGLV4UVvdPM5t0vEpLcSwarHnCkRK4BWRFeIc3KFRHoCzjZIuENd mq6G94AHWYof2F4m7ZIlbJbpRDn0Uam7+8CzwCpe21+3+u8B7COc2+uh5LkuG0f43Nln Tut9b8b7bYBt35cbLfmnBVu8Jrod8tIJBEhrGOnEdFY7U5WMg5YElxV9lcvqg0PvhKw0 AYcj7xbBiCoZ95XUBloWegaQh6mClYFU2IHt03SvM8K7P+7rOLAmLIWNieKQJ65Pz6e4 vntg==
- In-reply-to: <kru5ud$fse$1@ger.gmane.org>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <kru5ud$fse$1@ger.gmane.org>
On 14 July 2013 14:35, Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx> 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?
> for elem in $array
> do echo $elem[key]
> done
> """
>
> ./test.zsh:14: elem[key]: parameter not set
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
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author