Ugh. Bogged down...
Ken Ray
kray at sonsothunder.com
Fri Jun 11 02:30:58 EDT 2004
> One of the lines provided to me says:
>
> repeat for each line tLine in tData
>
> As I'm working with further 'massaging' of the grabbed text,
> I'm playing with some of this code and this one left me
> scratching my head (and there ain't a lot of hair up there!)
> -- what is the function of the (variable?) tLine in this
> text? I didn't see it previously declared in the script and
> wondered why this wouldn't simply be:
>
> repeat for each line in tData
>
> Instead. Again, I'm sure I missed something important, but I
> really AM paying attention.
Hey, Bob...
The reason is that there needs to be a variable which holds the line of data
in tData. This is tLine. If you had:
repeat for each line in tData
what variable would hold the current line's worth of info? So this:
repeat for each line tLine in tData
causes tLine to be filled with the contents of the current line each time
through the loop. The "repeat for each" construct is *incredibly fast*.
There is only one caveat, though, that that is you can't do anything with
tData while you're in the "repeat for each" loop. If you do, unexpected
things will happen. However most of the time you don't need to do anything
with tData, but just need to extract data from it to use elsewhere.
For example, suppose you wanted to retrieve all the lines of tData that
contains "hammer". This would be a quick way to do it:
put "" into tHammerLines
repeat for each line tLine in tData
if tLine contains "hammer" then
put tLine & cr after tHammerLines
end if
end repeat
delete last char of tHammerLines -- removes extra CR
There are a whole bunch of tips related to performance - I would recommend
taking a look at my site:
http://www.sonsothunder.com/devres/revolution/revolution.htm
specifically those tips that deal with these kinds of performance issues
("Increasing Script Performance, Parts I-III"):
http://www.sonsothunder.com/devres/revolution/revolution.htm?_scrp005
http://www.sonsothunder.com/devres/revolution/revolution.htm?_scrp006
http://www.sonsothunder.com/devres/revolution/revolution.htm?_scrp007
> I also wanted to comment that one of the reasons I decided to
> go with Revolution instead of any of the other suggestions is
> the tone and helpfulness of the members of this list. I'm
> glad to be a member of a list where everyone seems to want to
> share ideas, rather than berate the newbies or 'one-up' the
> others on the list. Hopefully the developers remember those
> who bought in at the ground floor when they're rich and
> famous... (For those of you who've been around the Mac arena
> since 1983 (yes, I said "3"), think HyperCard, and FirstClass, etc.)
Been there!
HTH,
Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
More information about the use-livecode
mailing list