From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15049 invoked by alias); 27 Feb 2015 12:46:37 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19929 Received: (qmail 13632 invoked from network); 27 Feb 2015 12:46:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,UNPARSEABLE_RELAY autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dyne.org; s=mail; t=1425041181; bh=KXh9zeKBc4rkL2Upsnx4yta7DzZ/SGV8f1D5rzZFCTM=; h=Date:From:To:Subject:References:In-Reply-To:From; b=mW0E6hqhkyKXbwuT+SJEuPIm96/ogHFngv1qPjGBYEZ2KOqkmhrcvDzkefJ9VjKmG l7HZq0KLFNHmzyawAn8ob09jObdiRca940ggrsUTRwMFIt6EJdBMeq1zxnjtO4aHgg 2hz7zc8/dhI9yJgYURbJ7WMh03f4QlAVmVZEtah4= Date: Fri, 27 Feb 2015 13:46:41 +0100 From: Jaromil To: zsh-users@zsh.org Subject: Re: pointers and associative maps Message-ID: <20150227124641.GA17275@fork> References: <20150227120941.GA15885@fork> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20150227120941.GA15885@fork> Organization: Dyne.org Free Software Foundry X-GPG-Keyserver: pgp.mit.edu X-GPG-Id: 4ACB7D10 [expires: 2018-09-05] X-GPG-Fingerprint: 6113 D89C A825 C5CE DD02 C872 73B3 5DA5 4ACB 7D10 User-Agent: Jaro Mail whopsie On Fri, 27 Feb 2015, Jaromil wrote: > The problem arises when I want to iterate through values, because using > a pointer modifier (P) and key/value modifiers (k)|(v) I get out only > the first char of the map field, not the whole string. I guess this is > related to the scoping of modifiers? here is how I do it: > > # _map is the variable holding the name of the associative map > > _num="${(P)#_map}" > for c in {1..$_num}; do > sysread -o 1 <> $_path > $_map+=("${${(Pk)_map}[$c]}" "${${(Pv)_map}[$c]}") > EOF > > > presuming that ${${(Pk)_map}[$c]} and ${${(Pv)_map}[$c]} should give in result > the full string, but instead they return the first char of the string, as if > the map index does not apply to the map but to the string object, so to say. solved! using ${(Pv)${_map}[$c]} and sorry for the noise. I was confused by the fact that the code above in a function was not giving the same result as: print ${${(Pv)_map}[$c]} This might be something to look into, basically the automatic scoping changes. however the formula above is the right solution, I guess it has a more explicit scoping of modifiers. again thanks for ZSh, its an awesome portable tool. I'll do my best to contribute to it in some future, perhaps some extensions based on libraries I've written. ciao