From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20706 invoked from network); 30 Mar 2004 17:22:53 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 30 Mar 2004 17:22:53 -0000 Received: (qmail 7153 invoked by alias); 30 Mar 2004 17:22:40 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 19709 Received: (qmail 7114 invoked from network); 30 Mar 2004 17:22:39 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 30 Mar 2004 17:22:39 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [130.225.247.86] by sunsite.dk (MessageWall 1.0.8) with SMTP; 30 Mar 2004 17:22:39 -0000 Received: (qmail 7078 invoked from network); 30 Mar 2004 17:22:38 -0000 Received: from mail36.messagelabs.com (193.109.254.211) by a.mx.sunsite.dk with SMTP; 30 Mar 2004 17:22:36 -0000 X-VirusChecked: Checked X-Env-Sender: okiddle@yahoo.co.uk X-Msg-Ref: server-6.tower-36.messagelabs.com!1080667328!5086404 X-StarScan-Version: 5.2.10; banners=-,-,- X-Originating-IP: [158.234.9.163] Received: (qmail 26485 invoked from network); 30 Mar 2004 17:22:08 -0000 Received: from iris.logica.co.uk (158.234.9.163) by server-6.tower-36.messagelabs.com with SMTP; 30 Mar 2004 17:22:08 -0000 Received: from trentino.logica.co.uk ([158.234.142.61]) by iris.logica.co.uk (8.12.3/8.12.3/Debian -4) with ESMTP id i2UHM8Ck012260; Tue, 30 Mar 2004 18:22:08 +0100 Received: from trentino.logica.co.uk (localhost [127.0.0.1]) by trentino.logica.co.uk (Postfix) with ESMTP id 900157969EA1; Tue, 30 Mar 2004 19:21:23 +0200 (CEST) Cc: zsh-workers@sunsite.dk X-VirusChecked: Checked X-StarScan-Version: 5.0.7; banners=.,-,- In-reply-to: <200403292014.40540.jonathan-hankins@mindspring.com> From: Oliver Kiddle References: <200403292014.40540.jonathan-hankins@mindspring.com> To: Jonathan Hankins Subject: Re: Bug with associative array and P flag? Date: Tue, 30 Mar 2004 19:21:23 +0200 Message-ID: <25113.1080667283@trentino.logica.co.uk> X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.0 required=6.0 tests=none autolearn=no version=2.63 X-Spam-Hits: 0.0 Jonathan Hankins wrote: > Below are two examples of using the P flag to variable expansion to access an > array indirectly. When using a regular array (foo), this works correctly. > However, when using an associative array in the same way, I get the value of > the first (alphabetically? randomly?) key (animal) regardless of the key I > use. Should the P flag work with the associative array in the same way as it > does with the regular array? This isn't so much a bug as a design limitation. It has nothing in particular to do with the P flag. Note that: print ${${bar}[color]} would print `cat' just like ${${(P)ref}[color]} Note also: % print $bar cat apple red What is happening is that the inner expansion is returning this as an array of three items. Using [color] as an index is then equivalent to using [0] because it is taken as a regular array index and hence a math expression. Note the difference if you assign color=2 first. Ideally, we would need an explicit (v) for it to work this way. For this to work, I think we will need the long overdue major changes to the parameter code. That's because I don't think the nested expansion code handles anything other than scalars and arrays for the nested parameters. Oliver