From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22082 invoked from network); 8 May 2006 15:31:28 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.1 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 8 May 2006 15:31:28 -0000 Received: (qmail 50355 invoked from network); 8 May 2006 15:31:21 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 8 May 2006 15:31:21 -0000 Received: (qmail 7919 invoked by alias); 8 May 2006 15:31:12 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10228 Received: (qmail 7907 invoked from network); 8 May 2006 15:31:11 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 8 May 2006 15:31:11 -0000 Received: (qmail 49045 invoked from network); 8 May 2006 15:31:11 -0000 Received: from cluster-c.mailcontrol.com (168.143.177.190) by a.mx.sunsite.dk with SMTP; 8 May 2006 15:31:10 -0000 Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly10c.srv.mailcontrol.com (MailControl) with ESMTP id k48FJWFS015988 for ; Mon, 8 May 2006 16:30:58 +0100 Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Mon, 8 May 2006 16:29:26 +0100 Date: Mon, 8 May 2006 16:29:56 +0100 From: Peter Stephenson To: zsh-users@sunsite.dk Subject: Re: substring extraction Message-Id: <20060508162956.5e7ec6d0.pws@csr.com> In-Reply-To: <20060508080745.GA5371@sc> References: <20060508080745.GA5371@sc> Organization: Cambridge Silicon Radio X-Mailer: Sylpheed version 2.0.4 (GTK+ 2.6.7; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 08 May 2006 15:29:26.0714 (UTC) FILETIME=[30ECC1A0:01C672B4] X-Scanned-By: MailControl A-06-00-04 (www.mailcontrol.com) on 10.67.0.120 "Stephane Chazelas" wrote: > In zsh: > > $var[2,3] > > zsh can do it because arrays and scalar variables are two > different types. In zsh, $var[2,5] gives the 2nd to 5th element > when $var is of array type, and 2nd to 5th char when $var is > scalar. In ksh/bash all variables are arrays and $var is a > shortcut for ${var[0]} (though it's not completely true of > bash). Just to point out you can combine the two in the same expression in zsh. As soon as you've extracted a single element, later suffixes work on characters. (One day this may be multibyte characters but that's not done yet.) % array=(one two three four) % print ${array[3][2,-2]} hre Since the rule is applied after every subscript match, you can do bizarre stuff like: % print ${array[1,3][-1][2,-2][2]} r which works in the following steps: array one two three four -> [1,3] array one two three -> [-1] scalar three -> [2,-2] scalar hre -> [2] scalar r -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php