From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11281 invoked from network); 21 Oct 2004 12:39:24 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 21 Oct 2004 12:39:24 -0000 Received: (qmail 21480 invoked from network); 21 Oct 2004 12:39:18 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 21 Oct 2004 12:39:18 -0000 Received: (qmail 6030 invoked by alias); 21 Oct 2004 12:39:10 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8086 Received: (qmail 6015 invoked from network); 21 Oct 2004 12:39:09 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 21 Oct 2004 12:39:09 -0000 Received: (qmail 20265 invoked from network); 21 Oct 2004 12:38:37 -0000 Received: from mxfep02.bredband.com (195.54.107.73) by a.mx.sunsite.dk with SMTP; 21 Oct 2004 12:38:35 -0000 Received: from puritan.pcp.ath.cx ([213.112.43.197] [213.112.43.197]) by mxfep02.bredband.com with ESMTP id <20041021123834.MVSE11981.mxfep02.bredband.com@puritan.pcp.ath.cx> for ; Thu, 21 Oct 2004 14:38:34 +0200 Received: by puritan.pcp.ath.cx (Postfix, from userid 1000) id 9B856AE041; Thu, 21 Oct 2004 14:38:35 +0200 (CEST) Date: Thu, 21 Oct 2004 14:38:35 +0200 From: Nikolai Weibull To: zsh-users@sunsite.dk Subject: Re: Associative Arrays Message-ID: <20041021123835.GF9224@puritan.pcp.ath.cx> References: <20041020195348.GJ11322@puritan.pcp.ath.cx> <20041021110526.GE1740@frhdtmp102861.morse.corp.wan> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20041021110526.GE1740@frhdtmp102861.morse.corp.wan> User-Agent: Mutt/1.5.6i X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: * X-Spam-Status: No, hits=1.5 required=6.0 tests=RCVD_IN_SORBS autolearn=no version=2.63 X-Spam-Hits: 1.5 * Stephane Chazelas [Oct 21, 2004 13:10]: > > 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} aha, OK. How very useful. > > 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. > 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}}") Aha, double quotation and then dequoting. What a bitch...is this seriously the simplest/only ways to do it? I'd say that shell programming would be a lot simpler as a whole if this was simpler. Still, I guess I'm thinking a bit too much like a Ruby or C programmer. nikolai -- ::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka ::: ::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden ::: ::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 ::: main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}