From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19052 invoked by alias); 5 Mar 2015 22:26:11 -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: 19975 Received: (qmail 14325 invoked from network); 5 Mar 2015 22:26:06 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 Date: Thu, 5 Mar 2015 23:16:56 +0100 From: Roman Neuhauser To: Bart Schaefer Cc: zsh-users@zsh.org Subject: Re: wrong array range with (r) flag on scalar? Message-ID: <20150305221656.GH4524@isis.sigpipe.cz> References: <20150305083000.GA3294@localhost.localdomain> <150305084408.ZM20963@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline In-Reply-To: <150305084408.ZM20963@torch.brasslantern.com> User-Agent: Mutt/1.5.23 (2014-03-12) # schaefer@brasslantern.com / 2015-03-05 08:44:08 -0800: > Would you expect > > torch% print $a[(r)h?,(r)wo] > hello wo > > to stop at the "w"? yes, but only *after* reading this carefully: r Reverse subscripting: if this flag is given, the exp is taken as a pattern and the result is the first matching array element, substring or word (if the parameter is an array, if it is a scalar, or if it is a scalar and the `w' flag is given, respec- tively). The subscript used is the number of the matching ele- ment, so that pairs of subscripts such as `$foo[(r)??,3]' and `$foo[(r)??,(r)f*]' are possible if the parameter is not an associative array. note: "The subscript used is the number of the matching element". i would definitely expect a (0-based indexing, pseudocode) `substr foobar bar` to be 3, not 5. > The doc could certainly be more clear about this. oh yeah. :) -- roman