Re: What is process_lines? and general complaint on the new manual

new topic     » goto parent     » topic index » view thread      » older message » newer message

Given your text input file 'namelist.txt'
containing

Amy
Matt
Robert
Craig
David
Ali
Joan
Arthur Lee

the following will work

 
include std/io.e 
 
constant TERMINATE = 1 
constant PROCEED   = 0 
 
function printNames(sequence aLine, integer line_no, object data) 
   writefln( data[1], { line_no, aLine }) 
   if data[2] > 0 and line_no = data[2] then 
      return TERMINATE 
   else 
      return PROCEED 
   end if 
end function 
 
function filterNames(sequence aLine, integer line_no, object data) 
   if equal(aLine[1], data[1]) then 
      nameList &= { aLine } 
   end if 
   return PROCEED 
end function 
 
--// print first 5 names 
process_lines("namelist.txt", routine_id("printNames"), {"[1z:4] : [2]", 5}) 
 
--// gather all names beginning with 'A' 
sequence nameList = {} 
process_lines("namelist.txt", routine_id("filterNames"), {'A'}) 
for i = 1 to length(nameList) do 
   printf(1, "%s\n", { nameList[i] }) 
end for 
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu