zsh-users
 help / color / mirror / code / Atom feed
* When (K) hash subscript flag could be useful?
@ 2017-10-02 13:44 Sebastian Gniazdowski
  2017-10-02 16:54 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Gniazdowski @ 2017-10-02 13:44 UTC (permalink / raw)
  To: Zsh Users

Hello,
I was stress testing the new hash assignment syntax for dash problems (because of having regrets about not doing this before -pcre_match regression revealed itself). Didn't find problems, but incidentally I stumbled upon ${harr[(K)...]}. Completion says:

K  -- all values where subscript matched by key as pattern

I finally decoded this – it takes keys of hash, treats them as patterns, and compares to subscript. So:

% local -A harr; harr=( 1\* 2- ); typeset -p1 -- harr; print -rl "${harr[(K)1-aaa]}"
typeset -A harr=(
  ['1*']=2-
)
2-

So this is reverse to what is expected: return keys, but match subscript-query to values. However passing (k) flag to match-values (R) subscript-flag does what's expected:

% local -A harr; harr=( 1- 2- ); typeset -p1 -- harr; print -rl "${(k)harr[(R)2-*]}"
typeset -A harr=(
  [1-]=2-
)
1-

I suspect (K) was added for versality. But maybe there are know applications of such "hash = database of patterns" construct?

--  
Sebastian Gniazdowski
psprint /at/ zdharma.org


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-02 17:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-02 13:44 When (K) hash subscript flag could be useful? Sebastian Gniazdowski
2017-10-02 16:54 ` Bart Schaefer
2017-10-02 17:51   ` Sebastian Gniazdowski

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).