Repeat for each

Geoff Canyon gcanyon at inspiredlogic.com
Fri Nov 4 20:40:52 EST 2005


On Nov 4, 2005, at 2:23 PM, Sarah Reichelt wrote:

>   filter theData with "*word*"

You could probably get just the lines with "word" in the second item  
by doing something like this:

filter theData with "*" & tab & "*word*" & tab & "*" & \
     tab & "*" & tab & "*" & tab & "*" & tab & "*" & tab & "*"

If memory serves though, both of these end up slower than the repeat  
for each method, surprisingly. Just tested: on 5000 lines of data, this:

on mouseUp
   put fld 1 into x
   set the itemdelimiter to tab
   put ticks() into t
   repeat 20
     put x into y
     put empty into z
     repeat for each line L in y
       if item 2 of L contains "word" then put L & cr after z
     end repeat
   end repeat
   put ticks() - t
   put char 1 to -2 of z into fld 2
end mouseUp

returns a time roughly two-thirds that of this:

on mouseUp
   put fld 1 into x
   put ticks() into t
   repeat 20
     put x into y
     filter y with "*word*"
   end repeat
   put ticks() - t
   put y into fld 2
end mouseUp

And the second solution doesn't even check afterward to see that  
"word" was in the second item!

My suggested filter at the top is slower still.

Both solutions seem to scale linearly, so repeat for each is probably  
the way to go regardless of the size of your data set.



More information about the use-livecode mailing list