From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29365 invoked by alias); 26 Mar 2017 21:55:39 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 40904 Received: (qmail 14889 invoked from network); 26 Mar 2017 21:55:39 -0000 X-Qmail-Scanner-Diagnostics: from mail.cs.uni-magdeburg.de by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(141.44.21.48):SA:0(-0.0/5.0):. Processed in 1.225382 secs); 26 Mar 2017 21:55:39 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RP_MATCHES_RCVD autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: elkner@cs.uni-magdeburg.de X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at cs.uni-magdeburg.de does not designate permitted sender hosts) Date: Sun, 26 Mar 2017 23:55:32 +0200 From: Jens Elkner To: zsh-workers@zsh.org Subject: Re: get keys of an associative array? Message-ID: <20170326215532.GA13200@trex.cs.ovgu.de> Mail-Followup-To: zsh-workers@zsh.org References: <20170326191828.GA13089@trex.cs.ovgu.de> <20170326203446.45f5883e@ntlworld.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170326203446.45f5883e@ntlworld.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Milter: milter4j - Mail Filter for Java 1.1.4 (b767) X-Milter: ClamAV 0.98.1-jel on mail - Status: Clean X-RcptTo: zsh-workers@zsh.org On Sun, Mar 26, 2017 at 08:34:46PM +0100, Peter Stephenson wrote: > On Sun, 26 Mar 2017 21:18:28 +0200 > Jens Elkner wrote: > > I've KSH_ARRAYS (beside KSH_GLOB KSH_TYPESET KSH_OPTION_PRINT) set, > > however, getting the key set of an array via ${!vname[@]} (as usually > > done within ksh or bash) does not work (bad substitution). > > That's never been implemented; it may be too far away from how zsh works > to do usefullly. Ah ok, thought initially, can't be so hard to check, whether the first char after a '${' is a '#' or '!' or ' ' ... Life would be much easier ;-) > > Couldn't find anything else, except the @k flag, but this doesn't work > > as well, e.g. > > > > unset A; typeset -A A; A['a']=1; A['b']=2; A['c']=3 ; print "${(@k)A}" > > > > should print 'a b c' but prints '3'. Bug, feature? Hmmm, any hints? > > You need "${(k)A[@]}" in ksh mode, but I'm not sure why the (@) flag > doesn't do the trick. Ahh, yes - this works. Also found out, that if I 'setopt no_KSH_ARRAYS' "${(@k)A}" works as well (but is inconvinient). > As it's an associative array you get the keys > back unordered. Yepp. That's expected for hash sets. Thanx a lot, jel. -- Otto-von-Guericke University http://www.cs.uni-magdeburg.de/ Department of Computer Science Geb. 29 R 027, Universitaetsplatz 2 39106 Magdeburg, Germany Tel: +49 391 67 52768