reading from a file

John Ridge ridge11103 at btinternet.com
Mon Jun 13 02:39:30 EDT 2005


on 12/6/05 7:32 pm,  Dennis Brown wrote :

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

***********************
Thanks, Dennis. That looks very interesting. I'm trying to build a stack "on
the fly", reading in a number of text fields for each card - they may
contain return, eol etc characters, so I must write out my own delimiters
when I export the card contents. What you've suggested is that I need two
delimiters - a "line" delimiter to mark the end of a card, and an "item"
delimiter to separate the fields. Then I can try your double "for each"
approach - I'll let you know.

John

-- 




More information about the use-livecode mailing list