Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Associative Arrays
- X-seq: zsh-users 8085
- From: Stephane Chazelas <Stephane.Chazelas@xxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Associative Arrays
- Date: Thu, 21 Oct 2004 12:05:28 +0100
- In-reply-to: <20041020195348.GJ11322@xxxxxxxxxxxxxxxxxx>
- Mail-followup-to: zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20041020195348.GJ11322@xxxxxxxxxxxxxxxxxx>
On Wed, Oct 20, 2004 at 09:53:48PM +0200, Nikolai Weibull wrote:
> I'm have a few questions regarding associative arrays. What exactly is
> the A flag for parameter expansion for? I mean, how does one use it,
> and how does one use the AA flag?
Not very useful, except maybe to avoid the use of typeset.
typeset -A a
a=(foo bar)
can be written:
: ${(AA)=a::=foo bar}
> Is there any way to pass an associative array as ONE argument to a
> function and easily deal with it as the same associative array in the
> other function? The easiest way seems to be the "pass-by-reference"
> technique, where one simply passes the name of the array and then use
> the P flag to deal with it.
> nikolai
You could use "${${(@qqkv)A}[*]}"
$ typeset -A A
$ A=("foo" "b bar" \' \" "" q)
$ print -lr "${${(@qqkv)A}[*]}"
'' 'q' 'foo' 'b bar' ''\''' '"'
So that in the function you can have
typeset -A local_hash
eval "local_hash=($1)"
or:
typeset -A local_hash
local_hash=("${(Q@)${(z)1}}")
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author