A chunking mystery

David Coker davidocoker at gmail.com
Sat Mar 15 22:08:52 EDT 2008


On Thu, Mar 13, 2008 at 11:20 PM, Phil Davis <revdev at pdslabs.net> wrote:
> Hi David,
>
>  I don't know if this is the total answer to your problem, but you're
>  mixing "repeat" forms.
>
>  Using the "repeat for each" form, you would normally examine the
>  contents of the line variable you named in the repeat. But your code
>  always check line 1 of the 'parent' container instead.
>
>  Try this:
>
> repeat for each line thisLine in tSource
>     if item 2 of thisLine <> "0" then
>       put tThisLine & cr after tCleanSource
>     end if
>  end repeat
>  delete last char of tCleanSource -- the trailing CR
>
>
>  Or if you want to use the "repeat with" form, try this:
>  repeat with x = the number of lines in tSource down to 1
>
>     if item 2 of line x of tSource = "0" then
>       delete line x of tSource
>     end if
>  end repeat
>
>  In the 2nd example, it's safest to go from end to beginning of the data
>  since you're deleting lines by their line number. Going from start to
>  end will cause the loop to skip a line whenever one is deleted.
>
>  Also, the first example will be faster. The larger your file, the more
>  you'll see the difference in speed.
>
>  Take care -
>  Phil Davis

Hello folks,
This is the first time I've had available to revisit this, but
certainly want to again thank you all for the suggestions.

Looks like Phil and Scott both came up with almost identical
solutions, so I'm gonna start working right there. As a side note, I
guess I'll need to spend some more time in the doc's doing a bit of
trial and error to better understand how the loops work in Rev.

>>Going from start to end will cause the loop
>>to skip a line whenever one is deleted.

Now there's a real "AhHa!" moment...

Thanks a bunch!
David



More information about the Use-livecode mailing list