Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: kinda perl split ...
- X-seq: zsh-users 10053
- From: dom@xxxxxxxxxxxxxxxx (Dominic Mitchell)
- To: Marc Chantreux <marc.chantreux@xxxxxxxxxxxxxxxxxx>
- Subject: Re: kinda perl split ...
- Date: Tue, 21 Mar 2006 13:51:18 +0000
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <442002B4.8080501@xxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <442002B4.8080501@xxxxxxxxxxxxxxxxxx>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author