rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* how would you do this in rc
@ 1991-12-20  0:09 Chris Siebenmann
  1991-12-20  1:11 ` DaviD W. Sanderson
  1991-12-20 12:21 ` David J. Fiander
  0 siblings, 2 replies; 4+ messages in thread
From: Chris Siebenmann @ 1991-12-20  0:09 UTC (permalink / raw)
  To: rc

 You have a list l and a string s. What's the most efficient way to not
merely find out if s exists in l, but to find its index in l if it does?
Is there an efficient method to do this? If there isn't, should there be? :)
[probably not; rc is not a general programming language, after all.]

	- cks


^ permalink raw reply	[flat|nested] 4+ messages in thread
* Re: how would you do this in rc
@ 1991-12-20  1:27 Tom Culliton x2278
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Culliton x2278 @ 1991-12-20  1:27 UTC (permalink / raw)
  To: cks; +Cc: rc

Use awk. ;-) ;-) ;-)  

Anything else would involve shifting through a copy of the list and
keeping a count with bc or something, or using bc to compute an index.
This is just off the top of my head and hasn't been tested...

# Invoked as: l=$mylist s=$mystring list_index
# there is probably a MUCH better way
fn list_index {
#	Is it even there?
	if (! ~ $l $s) {
		echo 0; return
	}
#	Go hunting for the first occurance
	cnt=1
	while (! ~ $l($cnt) $s) {
#		This is a bit gross...
		cnt=`{ echo $cnt + 1 | bc }
	}
#	Tell 'em where we found it
	echo $cnt
}


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

end of thread, other threads:[~1991-12-20 15:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-12-20  0:09 how would you do this in rc Chris Siebenmann
1991-12-20  1:11 ` DaviD W. Sanderson
1991-12-20 12:21 ` David J. Fiander
1991-12-20  1:27 Tom Culliton x2278

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).