From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13495 invoked from network); 21 Mar 2006 13:51:42 -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.5 required=5.0 tests=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; 21 Mar 2006 13:51:42 -0000 Received: (qmail 64570 invoked from network); 21 Mar 2006 13:51:35 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 21 Mar 2006 13:51:35 -0000 Received: (qmail 12544 invoked by alias); 21 Mar 2006 13:51:27 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10053 Received: (qmail 12534 invoked from network); 21 Mar 2006 13:51:26 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 21 Mar 2006 13:51:26 -0000 Received: (qmail 63348 invoked from network); 21 Mar 2006 13:51:26 -0000 Received: from happygiraffe.net (81.6.215.59) by a.mx.sunsite.dk with SMTP; 21 Mar 2006 13:51:22 -0000 Received: from localhost (localhost.happygiraffe.net [127.0.0.1]) by happygiraffe.net (Postfix) with ESMTP id 4AC3AB84D; Tue, 21 Mar 2006 13:51:19 +0000 (GMT) Received: from happygiraffe.net ([127.0.0.1]) by localhost (gimli.happygiraffe.net [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 74993-05-3; Tue, 21 Mar 2006 13:51:19 +0000 (GMT) Received: by happygiraffe.net (Postfix, from userid 1001) id 11159B84C; Tue, 21 Mar 2006 13:51:19 +0000 (GMT) Date: Tue, 21 Mar 2006 13:51:18 +0000 To: Marc Chantreux Cc: zsh-users@sunsite.dk Subject: Re: kinda perl split ... Message-ID: <20060321135118.GA92936@gimli.happygiraffe.net> References: <442002B4.8080501@ulpmm.u-strasbg.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <442002B4.8080501@ulpmm.u-strasbg.fr> User-Agent: Mutt/1.5.11 From: dom@happygiraffe.net (Dominic Mitchell) X-Virus-Scanned: amavisd-new at happygiraffe.net On Tue, Mar 21, 2006 at 02:42:12PM +0100, Marc Chantreux wrote: > Hi all, > > i'm always searching for shortest ways in zsh (coming from perl world). > > in perl : > > while ( <>) { > chomp; > my ( $a , $b ) = split /\t/; > print "b=$b a=$a" > } > > in zsh : > > while {read} { > content=( ${(ps:\t:)REPLY} ) > a=$content[1] > b=content[2] > print "b=$b a=$a" > } > > is there something more faster to initialize a and b (peraps closer than > split) ? Just use the read builtin: echo foo bar | while read a b junk do echo "a=$a b=$b" done I've got a habit of reading any remaining fields into a variable called "junk", just in case. -Dom