From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5133 invoked from network); 9 Aug 1998 16:41:33 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 9 Aug 1998 16:41:33 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id MAA29467; Sun, 9 Aug 1998 12:31:39 -0400 (EDT) Resent-Date: Sun, 9 Aug 1998 12:31:24 -0400 (EDT) Message-ID: <19980809123608.01170@astaroth.nit.gwu.edu> Date: Sun, 9 Aug 1998 12:36:08 -0400 From: Sweth Chandramouli To: ZSH Users Subject: Re: Re: sorting/uniq-ing an array? Mail-Followup-To: ZSH Users References: <19980809025636.18149@astaroth.nit.gwu.edu> <980809044123.ZM19065@candle.brasslantern.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89 In-Reply-To: <980809044123.ZM19065@candle.brasslantern.com> Resent-Message-ID: <"bdaDv1.0.tB7.SxSpr"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1711 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On Sun, Aug 09, 1998 at 04:41:23AM -0700, Bart Schaefer wrote: > On Aug 9, 2:56am, Sweth Chandramouli wrote: > : Subject: sorting/uniq-ing an array? > : > : i've come up with a way > : to remove redundant entries from an array (the appropriate part of > : my .zshrc is at the end of this message), but it's very slow > : > : is there a faster way to do this? > > Yes; > > typeset -U ports > > but the completion code makes its internal list of completions unique, > so it doesn't really help to remove the redundant entries from arrays > in advance when using them only for completion. that's good to know, though there are other places where it would be useful (such as the addpath fn i mentioned) to unique-ify. also, i was using portnums and portnames elsewhere, for non-completion purposes (see below). i actually had thought that there was some sort of typeset switch to do this, but did a man typeset, and didn't see any. i now realize that the typeset manpage on my machine is for the ksh and csh versions, and that the zsh one is only in the zshbuiltins manpage. what do people think of breaking the manpages for the builtins out of zshbuiltins (or rather, copying them out, since i think man zshall should still always be the reference of last resort), and maybe merging them in with the equivalent pages for other shell builtins? if there's an interest in it, i might take a stab at it; i just downloaded yodl, so i need a reason to learn it, and this is as good as any others i could conjure up. > You almost never need ${=...} when the "..." refers to an array. Using > ${=...} on an array causes the individual elements of the array to be > split into words, which is not very often what is wanted. So no, you > didn't do it right here: upon further consideration, this is a leftover ksh-ism in my brain-- i wasn't thinking of these as being in an array context, because in ksh an array without a subscript is actually just the last scalar in that array; i was then assuming that i needed to break the scalars that i was referencing up--hence the ${= constructs. > > : portnames=("${${${(f)$( : portnums=("${${${${${(f)$( : ports=(${=portnums} ${=portnames}) > > However, you're over-processing. You have both the port numbers and names > at one point during the portnums= computation, but then you throw the names > away. Keep them: > > ports=("${=${${(f)$( > (Note that there I used ${=...} to re-split the ${(f)...} array of lines, > so sometimes that _is_ what you want. I did say _almost_ never.) this works, which surprises me, since that implies that SH_WORD_SPLIT splits on either spaces or tabs (there are both in my /etc/services as delimiters between portnames and portnumbers); i thought that IFS was by default just a space. or am i just misunderstanding what you are doing here entirely? -- sweth. -- Sweth Chandramouli IS Coordinator, The George Washington University / (202) 994 - 8521 (V) / (202) 994 - 0458 (F) *