From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14200 invoked from network); 3 Apr 2005 17:49:23 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 3 Apr 2005 17:49:23 -0000 Received: (qmail 97556 invoked from network); 3 Apr 2005 17:49:15 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 3 Apr 2005 17:49:15 -0000 Received: (qmail 19260 invoked by alias); 3 Apr 2005 17:49:12 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21089 Received: (qmail 19250 invoked from network); 3 Apr 2005 17:49:11 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 3 Apr 2005 17:49:11 -0000 Received: (qmail 97259 invoked from network); 3 Apr 2005 17:49:11 -0000 Received: from vms048pub.verizon.net (206.46.252.48) by a.mx.sunsite.dk with SMTP; 3 Apr 2005 17:49:07 -0000 Received: from candle.brasslantern.com ([4.11.1.68]) by vms048.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix 0.04 (built Dec 24 2004)) with ESMTPA id <0IED00BC6THS98C0@vms048.mailsrvcs.net> for zsh-workers@sunsite.dk; Sun, 03 Apr 2005 12:49:05 -0500 (CDT) Received: from candle.brasslantern.com (IDENT:schaefer@localhost [127.0.0.1]) by candle.brasslantern.com (8.12.11/8.12.11) with ESMTP id j33Hn3oT004198; Sun, 03 Apr 2005 10:49:03 -0700 Received: (from schaefer@localhost) by candle.brasslantern.com (8.12.11/8.12.11/Submit) id j33Hn3Nn004197; Sun, 03 Apr 2005 10:49:03 -0700 Date: Sun, 03 Apr 2005 17:49:03 +0000 From: Bart Schaefer Subject: Re: ${(kv)foo[bar]} In-reply-to: <200504031435.19457.arvidjaar@newmail.ru> To: Andrey Borzenkov , zsh-workers@sunsite.dk Message-id: <1050403174903.ZM4196@candle.brasslantern.com> MIME-version: 1.0 X-Mailer: Z-Mail (5.0.0 30July97) Content-type: text/plain; charset=us-ascii References: <200504031435.19457.arvidjaar@newmail.ru> Comments: In reply to Andrey Borzenkov "${(kv)foo[bar]}" (Apr 3, 2:35pm) X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 On Apr 3, 2:35pm, Andrey Borzenkov wrote: } Subject: ${(kv)foo[bar]} } } print ${(kv)foo[bar]} } } should print "bar baz". Apparently it repsects only one flag in this case. That's why the doc for each of (k) and (v) has a special clause "Used with subscripts, ..." although I admit it could be clearer. This is actually a side-effect of the way subscripting was implemented before assocs even existed -- when the subscript is not a pattern form, the lower-level code is optimized [for lack of a better word] to avoid returning an array, so there's no way for both (k) and (v) to operate at once. Since, in this variation, you must already know the subscript for (k), it's most useful if the scalar that's returned is the value for (v). } Having it working would be handy e.g. in _arguments callbacks that } need to get options from command line; e.g. (current _urpmi) } } pkgs=( $(urpmq --list } ${(k)opt_args[--media]} ${(v)opt_args[--media]} } ${(k)opt_args[--searchmedia]} ${(v)opt_args[--searchmedia]} } 2> /dev/null } ) Isn't that a rather silly way to do it in any case? You don't need the subscript flags at all. Why not pkgs=( $(urpmq --list --media ${opt_args[--media]} --searchmedia ${opt_args[--searchmedia]} 2> /dev/null ) If for some reason you want to be deliberately obscure, you can force it with: pkgs=( $(urpmq --list ${(kv)opt_args[(i)--media]} ${(kv)opt_args[(i)--searchmedia]} 2> /dev/null ) The use of the (i) pattern-matching operator sends the subscript lookup through a different branch of the code where it's possible to return an array. Heck, you could even do: pkgs=( $(urpmq --list ${(kv)opt_args[(I)--*media]} 2> /dev/null )