[comp.lang.icon] What is the best way to do this?

hildum@ntmtv.UUCP (Eric Hildum) (06/07/90)

I am writing a procedure which scans a file for the objects that it 
includes, and returns the name of the object. Objects are included
via a line of the form:

*=> [chars]* COPY name

where name is the name of the object, COPY is a keyword, *=> marks the
beginning of the line, and [chars]* are any characters but the sequence
COPY. White space is ignored, and there are a random number of them on a 
line.

I have written the following procedure to open the files and generate
the names of objects included in the file.  The commented out portion is
a previous version of the loop body, and I have created a new loop body
using an if expression.  Which one of these is better, and why? If there 
is a better solution, I would like to see it.

					Thank you,
						Eric Hildum

procedure find_segments(name)

    local msource_file
    static segment_chars

    initial segment_chars := &ucase ++ &lcase ++ '0123456789'

    (msource_file := open(name, "r")) | stop("Unable to open: " || name)

    while line := read(msource_file) do 
#new
          line ? if (match("*=>") & tab(find("COPY") + 4)) then
                     { 
                     tab(upto(segment_chars)) 
                     suspend tab(many(segment_chars)) \ 1
                     }
#old
#	     suspend( line ? (match("*=>"),
#			      tab(find("COPY") + 4) , 
#			      tab(upto(segment_chars)) , 
#			      tab(many(segment_chars))) ) \ 1
				
    close(msource_file)

end