From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4150 invoked by alias); 2 Oct 2017 13:57:48 -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: 22916 Received: (qmail 25685 invoked by uid 1010); 2 Oct 2017 13:57:48 -0000 X-Qmail-Scanner-Diagnostics: from aok120.rev.netart.pl 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(85.128.245.120):SA:0(-1.9/5.0):. Processed in 2.384645 secs); 02 Oct 2017 13:57:48 -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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: psprint@zdharma.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Virus-Scanned: by amavisd-new using ClamAV (8) Date: Mon, 2 Oct 2017 15:44:25 +0200 From: Sebastian Gniazdowski To: Zsh Users Message-ID: Subject: When (K) hash subscript flag could be useful? X-Mailer: Airmail (442) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello, I was stress testing the new hash assignment syntax for dash problems (be= cause of having regrets about not doing this before -pcre=5Fmatch regress= ion revealed itself). Didn't find problems, but incidentally I stumbled u= pon =24=7Bharr=5B(K)...=5D=7D. Completion says: K =C2=A0-- all values where subscript matched by key as pattern I finally decoded this =E2=80=93 it takes keys of hash, treats them as pa= tterns, and compares to subscript. So: % local -A harr; harr=3D( 1=5C* 2- ); typeset -p1 -- harr; print -rl =22=24= =7Bharr=5B(K)1-aaa=5D=7D=22 typeset -A harr=3D( =C2=A0 =5B'1*'=5D=3D2- ) 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-f= lag does what's expected: % local -A harr; harr=3D( 1- 2- ); typeset -p1 -- harr; print -rl =22=24=7B= (k)harr=5B(R)2-*=5D=7D=22 typeset -A harr=3D( =C2=A0 =5B1-=5D=3D2- ) 1- I suspect (K) was added for versality. But maybe there are know applicati= ons of such =22hash =3D database of patterns=22 construct=3F -- =20 Sebastian Gniazdowski psprint /at/ zdharma.org