Tim wrote:
> I would like to read a text file a line at a time. What's more, I would
like to read each line into a variable. After looking at the draft manual
and reading fillines.html, I attempted the following code:

> file: open/read %test.txt
> foreach line file [print line]
> ;like to replace the above line of code
> ;with one that reads into a variable
> ;perhaps for parsing or modification
> ;and then prints it
> close text
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> {The second line of code generates an error message}


You're sooooo close. It's your experience in C that's tripping you up. Have
a read of the manual again at the page you say you've read, fillines.html:

<Quote>
For example, to read a file as a block of lines:

read/lines %file.txt

The block contains a series of strings without line terminators.
</Quote>

Try executing it at the REBOL console and look at the result.

Here's where you went wrong:
> file: open/read %test.txt

Here you're actually opening a read port to the file %test.txt. If your file
is really, really big, greater than megabytes in size, opening a port is the
way to go. But for smaller files, ones intended to be viewed at the console,
this is better:

"...read a text file a line at a time..."
        File: read/lines %test.txt
; File contains entire file as block of lines.


> foreach line file [print line]

"...to read each line into a variable..."
"...reads into a variable,
perhaps for parsing or modification,
and then prints it..."

        foreach line File [
            append line "My modification"
            print line
            ]

> close text

Don't need this. If you want to release the memory held by File, do this:
        File: none
    and it's gone.

> I'd like to make a comment here: I learned C starting about 9 years ago,
with my main reference called (if I remember correctly), "The C Users
Bible". It had a very special rule. EVERY EXAMPLE WAS FULLY EXECUTABLE!!
Nothing taken out of context.
>
> I believe if Rebol makes this a goal, for a manual, you can kick some Perl
butt out there in Cyber Land. These first tiny steps for any newbie are as
important as showing off the power of Rebol.
>
> Now you have it in writing: If I can help to this end, just ask.

The REBOL script for the manual already executes each example, except for
the examples for 'quit, 'ask and a couple of others, if I recall correctly.
Have a look at the beta manual script at the http://www.rebol.com site and
check it out.

Don't be put off, you are on the learning path.

REBOL - It's better than you think!

Hmmmm... Looks like I'm sloganeering again...

Andrew Martin
A return to innocence...
ICQ: 26227169
[EMAIL PROTECTED]
http://members.xoom.com/AndrewMartin/
-><-

Reply via email to