remove empty lines

Richard Gaskin ambassador at fourthworld.com
Thu Aug 3 00:42:16 EDT 2006


Alex Tweedly wrote:

>... you could do it like
> 
>> put fld 'emailList' into tEmailList
>> put empty into tNewEmail
>> repeat for each line tEmail in tEmailList
>>    if line tEmail is not empty then
>>       put tEmail & CR after tNewEmailList
>>   end if
>> end repeat
>> put tNewEmailList into fld 'emailList'
> 
> 
> but easier would be
> 
>> put fld 'emailList' into tEmailList
>> filter tEmailList without empty
>> put tEmailList into fld 'emailList'

Easier to script, yes, but note the result from running this script 
which compares both methods:


on mouseUp
   put 1000 into N
   put fld 1 into tData
   --
   --
   -- 1. repeat for each
   --
   put the millisecs into t
   repeat N
     --
     put empty into R1
     repeat for each line tLine in tData
       if tLine is not empty then
         put tLine &cr after R1
       end if
     end repeat
     delete last char of R1
     --
   end repeat
   put the millisecs - t into t1
   --
   --
   -- 2. filter:
   --
   put the millisecs into t
   repeat N
     --
     put tData into R2
     filter R2 without empty
     --
   end repeat
   put the millisecs - t into t2
   --
   --
   -- Result:
   put t1 && t2
end mouseUp


Did I write this wrong?

Seems most times I benchmark "repeat for each" with the well-optimized 
"put after" I get results that hold up surprisingly well.

I have another post in the works with some other interesting benchmarks 
related to processing lists (things I learned on summer vacation <g>)...

--
  Richard Gaskin
  Managing Editor, revJournal
  _______________________________________________________
  Rev tips, tutorials and more: http://www.revJournal.com



More information about the use-livecode mailing list