zsh-workers
 help / color / mirror / code / Atom feed
From: "Benjamin R. Haskell" <zsh@benizi.com>
To: Greg Klanderman <gak@klanderman.net>
Cc: Zsh list <zsh-workers@zsh.org>
Subject: Re: 'K' subscript flag with associative array?
Date: Tue, 1 Mar 2011 12:13:02 -0500 (EST)	[thread overview]
Message-ID: <alpine.LNX.2.01.1103011202030.2792@hp> (raw)
In-Reply-To: <19821.9197.225140.311873@gargle.gargle.HOWL>

On Tue, 1 Mar 2011, Greg Klanderman wrote:

>
> Hi guys, what am I doing wrong here?  Shouldn't this:
>
>  zsh% echo ${(k)functions[(K)_*]}
>
> give all function names starting with '_'?

You want:

${functions[(I)_*]}


If I'm reading the man page right, I'd interpret your attempt as:

the list of functions whose names, when taken as patterns, match the 
literal string: '_*'

K treats the keys as patterns.

Most function names don't contain pattern metachars, so when taken as 
patterns, only match their own names.

But, for example:

$ '??' () { echo question everything }
$ print -l ${(k)functions[(K)_*]}
??
# because the key '??' matches any two characters
$ print -l ${(k)functions[(K)lj]}
??

Not sure what the utility is, though.  Something like this, I guess?

$ typeset -A featureset
$ featureset=( '*.*' hasadot 'test.*' 'test function' )
$ print -l ${featureset[(K)lkjlkjljk.ojojojoj]}
hasadot
$ print -l ${featureset[(K)test.function]}
hasadot
test function

-- 
Best,
Ben


      parent reply	other threads:[~2011-03-01 17:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-01 16:50 Greg Klanderman
2011-03-01 17:09 ` Mikael Magnusson
2011-03-01 17:20   ` Benjamin R. Haskell
2011-03-01 17:28     ` Mikael Magnusson
2011-03-01 18:08   ` Greg Klanderman
2011-03-01 17:13 ` Benjamin R. Haskell [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LNX.2.01.1103011202030.2792@hp \
    --to=zsh@benizi.com \
    --cc=gak@klanderman.net \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).