zsh-users
 help / color / mirror / code / Atom feed
* sorting/uniq-ing an array?
@ 1998-08-09  6:56 Sweth Chandramouli
  1998-08-09 11:41 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Sweth Chandramouli @ 1998-08-09  6:56 UTC (permalink / raw)
  To: ZSH Users

	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)$(</etc/services)}:#\#*}%%[        ]*}")
portnums=("${${${${${(f)$(</etc/services)}:#\#*}%%/*}##*        }##* }")
ports=(${=portnums} ${=portnames})
# unique-ify ports
for i in $ports ; do
   unset append;
   for b in ${=tmpvar} ; do
      if [[ $i == $b ]] ; then
         append='false';
      fi;
   done;
   if [[ -z $append ]] ; then
      tmpvar=($tmpvar $i);
   fi;
done;
ports=(${=tmpvar});
--- end quoted text ---

-- 
Sweth Chandramouli
IS Coordinator, The George Washington University
<sweth@gwu.edu> / (202) 994 - 8521 (V) / (202) 994 - 0458 (F)
<a href="http://astaroth.nit.gwu.edu/~sweth/disc.html">*</a>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1998-08-10 11:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-08-09  6:56 sorting/uniq-ing an array? Sweth Chandramouli
1998-08-09 11:41 ` Bart Schaefer
1998-08-09 16:36   ` Sweth Chandramouli
1998-08-09 17:50     ` Bart Schaefer
1998-08-10 11:34     ` Bruce Stephens

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).