reading from a file

Dennis Brown see3d at writeme.com
Sun Jun 12 14:32:20 EDT 2005


On Jun 12, 2005, at 1:06 PM, John Ridge wrote:
>
> I've tried another method that I thought might be faster - instead of
> reading a chunk at a time and popping it into a field on a new  
> card, why not
> gulp the whole file into a variable, then get each item as a chunk?
>
> In fact it's slower. Ah well...
> -- 

John,

The slowness comes from switching from sequential access of the file  
to "pseudo random access" by using chunk statements on the variable.   
If you read in the whole file into a variable, then split the  
variable by return, you will have an array of lines which can be  
randomly accessed quickly.  You can further put one of those lines  
into another variable and split it by some item delimiter, and have  
an array of items to process that line.

However, the fastest way to sequentially access the file read into a  
variable, is with a repeat for each construct.  It virtually lays  
rubber!

repeat for each line thisLine in wholeFileVariable
   repeat for each item thisItem in thisLine
     doSomethingWith thisItem
   end repeat
end repeat

Dennis


More information about the use-livecode mailing list