> 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}
>
Hi Tim:
I would do it something like this:
file: read/lines %test.txt ; read the file line by line
into a variable
z: length? file ; find out how many lines there
are
x: 0 ; use this variable to track
lines
loop z [ ; set up a line by line loop
x = x + 1 ; specify line number in
sequence
print pick file x ; print the current line number
]
In the loop, of course, you can add whatever you wish to manipulate each
individual lines.
You'll find REBOL elegantly simple for operations of this type.
--Ralph
- [REBOL] The forthcoming REBOL/V... jkinraid
- [REBOL] Re: The forthcoming REB... ejolson
- [REBOL] [REBOL] Update file as ... tjohnson
- [REBOL] [REBOL]Controlling secu... tjohnson
- [REBOL] [REBOL]Controlling secu... kracik
- [REBOL] [REBOL]Controlling secu... tim781
- [REBOL] [REBOL]Controlling secu... news . ted
- [REBOL] [REBOL]Controlling secu... tjohnson
- [REBOL] [REBOL]Controlling secu... joel . neely
- [REBOL] Re: Updating a file as a po... giesse
- [REBOL] Reading text a line at a time Re:(2) ralph
- [REBOL] Reading text a line at a time Re:(2) tjohnson
- [REBOL] Reading text a line at a time Re... joel . neely
- [REBOL] Re: Rebol Web Server giesse
- [REBOL] Rebol Web Server Re:(2) Petr . Krenzelok
- [REBOL] Rebol Web Server Re:(3) dado
- [REBOL] Rebol Web Server Re:(4) Petr . Krenzelok
- [REBOL] Rebol Web Server Re:(5) robert . muench
- [REBOL] Rebol Web Server Re:(6) joel . neely
- [REBOL] Rebol Web Server Re:(7) robert . muench
- [REBOL] Re: Rebol Web Server Re:(5) ejolson
