reading from a file

John Ridge ridge11103 at btinternet.com
Tue Jun 14 03:06:34 EDT 2005


on 13/6/05 1:50 pm,  Dennis Brown wrote :


On Jun 13, 2005, at 2:39 AM, John Ridge wrote:

> 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,

You can also do this with a single repeat for each.

repeat for each char thisCharacter in wholeFileVariable
    doSomethingWith thisCharacter
end repeat

See the example stack called read anything in RevOnline to see how it
is done.  If you can scan your file sequentially, you can do anything
you want to it in short order.  It just depends on the specific
details you want to accomplish.

Dennis


*******************

There was an earlier thread in which people remarked on the power (and
speed) of the "for each" structure. But I need to be beaten over the head
with an example relevant to a problem of my own!

The point I was making before is really about the "stack of cards" metaphor
- it is deeply built into xCard and of course Rev - and it makes a stack
essentially  two-dimensional as a data storage device. That is, there are
cards, and on each card there are fields. So you can picture cards as rows
and fields as columns, and read in a stream of data accordingly with "for
each", using a "card" delimiter and a "field" delimiter -   arbitrary
characters separating lines (cards), then nested within that a separation
into items (fields).

Of course it's only a metaphor. But it's a powerful user model. For example,
I'm finding it difficult to re-think in terms of using custom properties to
store data, in a stack with only one card - maybe I have to start with a
library of card simulation handlers (CreateCard, DeleteCard, GoNext etc). Or
has someone already done this? That would be nice :)

John
-- 




More information about the use-livecode mailing list