Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: When (K) hash subscript flag could be useful?
- X-seq: zsh-users 22917
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: When (K) hash subscript flag could be useful?
- Date: Mon, 2 Oct 2017 09:54:37 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=WtDHmBxGZSoFnSSchZgr6/AU2fYclmziXrW7llx7ReY=; b=j7yvqWdqJoEVs1mtwDe8mqnmXqrz5rheEVinU5m1HSYWpZs2cbsfInYr5CVC5dRvEv QIIQv3w9cM5Yucdr6JA/9i6azAL4VlTvG+SE51daQXdSLsJNzUz/jT4MYnyxBgaGjlPj cafSfZmKo959Pso8oe4aa7cE4d80lh8fwvENiEpc90vDmxQ26K3COcvNMAB+Umn8FeRt r8HhsuPCyMqvlw64UQbXkkujPxXAWLJxsZDTXvxnp0VLoo7RggHQVwS9ig+EUZGGB5PY 0B5vLL0Q3z6B9/kh5wX1MYtbWs5H/kOMzztZDtYxSOsQZBlHL7xaS0F+Gjkupjb98bom WW2A==
- In-reply-to: <etPan.59d242ba.35d2426e.98a8@zdharma.org>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <etPan.59d242ba.35d2426e.98a8@zdharma.org>
On Oct 2, 3:44pm, Sebastian Gniazdowski wrote:
}
} I stumbled upon ${harr[(K)...]}. Completion says:
}
} K -- all values where subscript matched by key as pattern
}
} So this is reverse to what is expected
Er, expected by who, why?
} I suspect (K) was added for versality. But maybe there are know
} applications of such "hash = database of patterns" construct?
It allows you to build something like a "case" statement where the
branches aren't established until run time. Instead of
case $x in
(...) y=$z;;
# ... etc. ...
esac
you can write
y=${z[(K)$x]}
It's also basically the same thing that "zstyle" does with context
lookup, except that zstyle layers on special treatment of using the
"best match" to always return a single result.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author