From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29323 invoked from network); 29 Jul 2005 13:32:54 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 29 Jul 2005 13:32:54 -0000 Received: (qmail 49380 invoked from network); 29 Jul 2005 13:32:48 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 29 Jul 2005 13:32:48 -0000 Received: (qmail 18807 invoked by alias); 29 Jul 2005 13:32:45 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21546 Received: (qmail 18798 invoked from network); 29 Jul 2005 13:32:44 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 29 Jul 2005 13:32:44 -0000 Received: (qmail 49070 invoked from network); 29 Jul 2005 13:32:44 -0000 Received: from mailhost1.csr.com (HELO MAILSWEEPER01.csr.com) (81.105.217.43) by a.mx.sunsite.dk with SMTP; 29 Jul 2005 13:32:37 -0000 Received: from exchange03.csr.com (unverified [10.100.137.60]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Fri, 29 Jul 2005 14:30:27 +0100 Received: from news01.csr.com ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Fri, 29 Jul 2005 14:34:57 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.1/8.12.11) with ESMTP id j6TDWWrY011941 for ; Fri, 29 Jul 2005 14:32:32 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.13.1/8.13.1/Submit) with ESMTP id j6TDWWJb011937 for ; Fri, 29 Jul 2005 14:32:32 +0100 Message-Id: <200507291332.j6TDWWJb011937@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: Re: Those array searching oddities again In-reply-to: <200507291157.j6TBv5Fx008185@news01.csr.com> References: <200507291157.j6TBv5Fx008185@news01.csr.com> Date: Fri, 29 Jul 2005 14:32:31 +0100 From: Peter Stephenson X-OriginalArrivalTime: 29 Jul 2005 13:34:57.0865 (UTC) FILETIME=[4FDE5390:01C59442] X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.4 Peter Stephenson wrote: > Probably there should be at least a warning in the documentation for (R)... This is slightly more logical, using (i) and (I) instead of the combination (k) and (r) and (R), with some cross-referencing in the appropriate places. This may well confuse someone reading it, but there is a quite good reason for that... Index: Doc/Zsh/params.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/params.yo,v retrieving revision 1.25 diff -u -r1.25 params.yo --- Doc/Zsh/params.yo 1 Apr 2005 12:04:22 -0000 1.25 +++ Doc/Zsh/params.yo 29 Jul 2005 13:26:33 -0000 @@ -201,11 +201,30 @@ possible if the parameter is not an associative array. If the parameter is an associative array, only the value part of each pair is compared to the pattern, and the result is that value. + +If a search through an ordinary array failed, the search sets the +subscript to one past the end of the array, and hence +tt(${array[(r)pattern]}) will substitute the empty string. Thus the +success of a search can be tested by using the tt((i)) flag, for +example (assuming the option tt(KSH_ARRAYS) is not in effect): + +example([[ ${array[(i)pattern]} -le ${#array} ]]) + +If tt(KSH_ARRAYS) is in effect, the tt(-le) should be replaced by tt(-lt). ) item(tt(R))( Like `tt(r)', but gives the last match. For associative arrays, gives all possible matches. May be used for assigning to ordinary array elements, but not for assigning to associative arrays. + +Note that this flag can give odd results on failure. For an ordinary array +the item substituted is that corresponding to subscript 0. If the option +tt(KSH_ARRAYS) is not in effect, this is the same as the element +corresponding to subscript 1, although the form tt(${array[(I)pattern]}) +will evaluate to 0 for a failed match. If the option tt(KSH_ARRAYS) is in +effect, the subscript is still 0 for a failed match; this cannot be +distinguished from a successful match without testing tt(${array[0]}) +against the pattern. ) item(tt(i))( Like `tt(r)', but gives the index of the match instead; this may not be @@ -213,10 +232,14 @@ behaves like `tt(r)'. For associative arrays, the key part of each pair is compared to the pattern, and the first matching key found is the result. + +See `tt(r)' for discussion of subscripts of failed matches. ) item(tt(I))( Like `tt(i)', but gives the index of the last match, or all possible matching keys in an associative array. + +See `tt(R)' for discussion of subscripts of failed matches. ) item(tt(k))( If used in a subscript on an associative array, this flag causes the keys -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. **********************************************************************