From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20340 invoked from network); 9 Aug 1998 07:15:54 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 9 Aug 1998 07:15:54 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id CAA26312; Sun, 9 Aug 1998 02:52:21 -0400 (EDT) Resent-Date: Sun, 9 Aug 1998 02:51:58 -0400 (EDT) Message-ID: <19980809025636.18149@astaroth.nit.gwu.edu> Date: Sun, 9 Aug 1998 02:56:36 -0400 From: Sweth Chandramouli To: ZSH Users Subject: sorting/uniq-ing an array? Mail-Followup-To: ZSH Users Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89 Resent-Message-ID: <"i_zch1.0.kQ6.ESKpr"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1709 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu while playing around with zsh completion, i noticed that the ports variable set in the comctl-examples file doesn't distinguish between tcp and udp services in /etc/services, resulting in a non-unique array (e.g. multiple instances of "echo"). 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--on a single-user ultrasparc/30, it adds about two seconds to my login time. is there a faster way to do this? for some uses, it's okay-- i've got a function called addpath, for example, that uses this sort of looping to scan $PATH to see if the argument passed to addpath is already in it, and iff it isn't, adds it, and a second or two to process that function (usually almost unnoticeable, actually, since $PATH is so much shorter than $ports) doesn't seem strange. as an addition to the login process, however, it seems like it takes an eternity. i was thinking of creating a file that stored the array, and on login, first populate $ports with the contents of that file, and then spawned a bg process to do the parsing from /etc/services, write the output out to the file, and then repopulate $ports. any suggestions on how to do that, or of other (quicker) ways to do the parsing of the array? (as always, of course, comments on style are also appreciated. i'm fairly certain that i still don't understand when ${= is needed and when it isn't, so i just tend to use it everywhere that splitting might be needed. did i do it right here?) tia, sweth. --- begin quoted text --- #### ports is made unique in an ugly way. is this fixable? portnames=("${${${(f)$( / (202) 994 - 8521 (V) / (202) 994 - 0458 (F) * From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29449 invoked from network); 9 Aug 1998 11:54:16 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 9 Aug 1998 11:54:16 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id HAA27939; Sun, 9 Aug 1998 07:40:49 -0400 (EDT) Resent-Date: Sun, 9 Aug 1998 07:40:39 -0400 (EDT) From: "Bart Schaefer" Message-Id: <980809044123.ZM19065@candle.brasslantern.com> Date: Sun, 9 Aug 1998 04:41:23 -0700 In-Reply-To: <19980809025636.18149@astaroth.nit.gwu.edu> Comments: In reply to Sweth Chandramouli "sorting/uniq-ing an array?" (Aug 9, 2:56am) References: <19980809025636.18149@astaroth.nit.gwu.edu> X-Mailer: Z-Mail (4.0b.820 20aug96) To: Sweth Chandramouli , ZSH Users Subject: Re: sorting/uniq-ing an array? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"njTgq1.0.3q6.sgOpr"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1710 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 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. : (as always, of course, comments on style are also appreciated. : i'm fairly certain that i still don't understand when ${= is needed : and when it isn't, so i just tend to use it everywhere that splitting : might be needed. did i do it right here?) 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: : portnames=("${${${(f)$( 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) * From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from candle.brasslantern.com (IDENT:schaefer@dynamic22.pm02.san-rafael.best.com [206.184.127.86]) by math.gatech.edu (8.9.1/8.9.1) with ESMTP id NAA00477 for ; Sun, 9 Aug 1998 13:48:49 -0400 (EDT) Received: (from schaefer@localhost) by candle.brasslantern.com (8.8.5/8.8.5) id KAA20529; Sun, 9 Aug 1998 10:50:28 -0700 From: "Bart Schaefer" Message-Id: <980809105027.ZM20528@candle.brasslantern.com> Date: Sun, 9 Aug 1998 10:50:27 -0700 In-Reply-To: <19980809123608.01170@astaroth.nit.gwu.edu> Comments: In reply to Sweth Chandramouli "Re: Re: sorting/uniq-ing an array?" (Aug 9, 12:36pm) References: <19980809025636.18149@astaroth.nit.gwu.edu> <980809044123.ZM19065@candle.brasslantern.com> <19980809123608.01170@astaroth.nit.gwu.edu> X-Mailer: Z-Mail (4.0b.820 20aug96) To: Sweth Chandramouli , ZSH Users Subject: Re: sorting/uniq-ing an array? X-Mailing-List: archive/latest/1712 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Aug 9, 12:36pm, Sweth Chandramouli wrote: } Subject: Re: Re: sorting/uniq-ing an array? } } 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 } maybe merging [zsh builtins manpages] with the equivalent pages for other } shell builtins? I don't think this is a good idea. For one thing, it means replacing the installed man pages of another app with the man pages from zsh, which may be impossible for many zsh installers. For another, it makes the manpages differ significantly from the info documentation. Then there's the issue of "merging" itself -- when do you propose that this happen? At the time zsh manual pages are installed? Even if we could somehow find, parse, and merge with the existing other shell's manpages, what happens when the other shell or its manpages are updated? } > 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? No, you understand; IFS is by default space, tab, newline, and nul: zagzig% echo $#IFS 4 zagzig% echo x${IFS}x | cat -v x ^@x zagzig% I don't think other shells have nul in IFS by default, but I'm not sure. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3170 invoked from network); 10 Aug 1998 11:42:43 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 10 Aug 1998 11:42:43 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id HAA08413; Mon, 10 Aug 1998 07:32:56 -0400 (EDT) Resent-Date: Mon, 10 Aug 1998 07:32:47 -0400 (EDT) Sender: B.Stephens@isode.com To: ZSH Users Subject: Re: sorting/uniq-ing an array? References: <19980809025636.18149@astaroth.nit.gwu.edu> <980809044123.ZM19065@candle.brasslantern.com> <19980809123608.01170@astaroth.nit.gwu.edu> Mime-Version: 1.0 (generated by tm-edit 7.108) Content-Type: text/plain; charset=US-ASCII From: Bruce Stephens Date: 10 Aug 1998 12:34:31 +0100 In-Reply-To: Sweth Chandramouli's message of "Sun, 9 Aug 1998 12:36:08 -0400" Message-ID: X-Mailer: Gnus v5.6.27/XEmacs 20.4 - "Emerald" Resent-Message-ID: <"ikMPq1.0.u22.Vfjpr"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1718 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Sweth Chandramouli writes: > 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. Ah, you want Tom Phelp's TkMan, which shows when there are multiple manpages with the same name, and provides a menu of them. . "typeset -U" works for arrays, and so works for path. Unfortunately, it doesn't work with (for example) LD_LIBRARY_PATH, which is a colon-separated list. Annoying: this really needs configurableness.