From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2184 invoked from network); 28 Jun 2001 08:28:27 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 28 Jun 2001 08:28:27 -0000 Received: (qmail 1940 invoked by alias); 28 Jun 2001 08:27:23 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 3969 Received: (qmail 1913 invoked from network); 28 Jun 2001 08:27:21 -0000 From: "Bart Schaefer" Message-Id: <1010628082349.ZM6944@candle.brasslantern.com> Date: Thu, 28 Jun 2001 08:23:48 +0000 In-Reply-To: <200106280801.KAA63855@numa1.igpm.rwth-aachen.de> Comments: In reply to jarausch@igpm.rwth-aachen.de "pop - is there a more elegant solution" (Jun 28, 10:01am) References: <200106280801.KAA63855@numa1.igpm.rwth-aachen.de> X-Mailer: Z-Mail (5.0.0 30July97) To: jarausch@igpm.rwth-aachen.de, zsh-users@sunsite.dk Subject: Re: pop - is there a more elegant solution MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Jun 28, 10:01am, jarausch@igpm.rwth-aachen.de wrote: } } is there a more elegant (less cryptic) solution to } # emulate Perl's pop function Depends on what you intend by emulating it. Functions in Bourne-like shell languages don't return values like functions in perl, so there isn't anything well-defined to do with the popped value. The fastest way to simply discard the last positional parameter is argv[-1]=() (which of course only works in zsh). So if what you want to do is to store that positional parameter in $last and then discard it, last=$argv[-1] argv[-1]=() is about as un-cryptic as you're going to get. } #!/bin/zsh } # get the last parameter and shorten the list } echo $@ } last=$[-1] You must mean $@[-1]. $[-1] is just -1. But if you know about $@[-1], then ... } # shorten the parameter array } set $@[0,$[-1+$#]] ... you should know that $@[1,-2] works as well. (You don't index from zero unless the ksh_arrays option is set.) Aside to zsh-workers: A weird thing about `setopt ksharrays' is that ${@[0]} is $1. Does ksh really work that way? -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net