From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25934 invoked from network); 9 Jul 2005 17:16:58 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 9 Jul 2005 17:16:58 -0000 Received: (qmail 90118 invoked from network); 9 Jul 2005 17:16:52 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 9 Jul 2005 17:16:51 -0000 Received: (qmail 9614 invoked by alias); 9 Jul 2005 17:16:43 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9074 Received: (qmail 9605 invoked from network); 9 Jul 2005 17:16:42 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 9 Jul 2005 17:16:42 -0000 Received: (qmail 89031 invoked from network); 9 Jul 2005 17:16:42 -0000 Received: from vms048pub.verizon.net (206.46.252.48) by a.mx.sunsite.dk with SMTP; 9 Jul 2005 17:16:38 -0000 Received: from candle.brasslantern.com ([71.116.88.149]) by vms048.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix 0.04 (built Dec 24 2004)) with ESMTPA id <0IJD00I7AENM30GE@vms048.mailsrvcs.net> for zsh-users@sunsite.dk; Sat, 09 Jul 2005 12:16:35 -0500 (CDT) Received: from candle.brasslantern.com (IDENT:schaefer@localhost [127.0.0.1]) by candle.brasslantern.com (8.12.11/8.12.11) with ESMTP id j69HGXPT017744 for ; Sat, 09 Jul 2005 10:16:34 -0700 Received: (from schaefer@localhost) by candle.brasslantern.com (8.12.11/8.12.11/Submit) id j69HGXfH017743 for zsh-users@sunsite.dk; Sat, 09 Jul 2005 10:16:33 -0700 Date: Sat, 09 Jul 2005 17:16:33 +0000 From: Bart Schaefer Subject: Re: Help parsing a file from one regex to another In-reply-to: <20050709064103.GC3825@localhost.localdomain> To: zsh-users@sunsite.dk Message-id: <1050709171633.ZM17742@candle.brasslantern.com> MIME-version: 1.0 X-Mailer: Z-Mail (5.0.0 30July97) Content-type: text/plain; charset=us-ascii References: <20050708073037.GB9744@localhost.localdomain> <1050708171627.ZM16747@candle.brasslantern.com> <20050709064103.GC3825@localhost.localdomain> Comments: In reply to Doug Kearns "Re: Help parsing a file from one regex to another" (Jul 9, 4:41pm) X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 On Jul 9, 4:41pm, Doug Kearns wrote: } Subject: Re: Help parsing a file from one regex to another } } I always forget that a non-matching pattern in the second expression } causes the rest of the array to be selected. Is this documented } somewhere that I'm missing? Hmm, no, I guess not. The way the (i) and (I) subscript flags work (on an ordinary array, not on an associative one) is that either they resolve to a matching index, or they "fall off" the array in the direction that they're searching and thus resolve to an index that has the correct magnitude but that can be distinguished from any successful match. So, given an array in which no element has the value "missing": $array[(I)missing] == 0 $array[(i)missing] == $(($#array+1)) This is so you can get sensible results from tests like if [[ $array[(i)foreward] -ge $array[(I)backward] ]]; then : ... fi Despite the documentation explaining (i) in terms of (r), the actual implementation of (r) is more like $array[$array[(i)missing]], so the side-effect of $array[0] being the same as $array[1] comes into play. ${(k)array[(R)missing]} == 0 ${(v)array[(R)missing]} == $array[1] ${(k)array[(r)missing]} == $(($#array+1)) ${(v)array[(r)missing]} == "" and $array[(R)missing,(r)missing] == $array[*] As a final note ... this behavior of (i) differs in really old versions of zsh, where (as I recall) a missing element was always resolved to 0, which meant that $array[$array[(i)missing]] != $array[(r)missing], which seemed like a bad thing, so it was changed.