Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Read question in Reb 3.0

 [1/11] from: raimunddold:web at: 14-Feb-2009 11:11


Hi, maybe I did not find the answer in the docs, but anyway. In R2.0 I regularly used something like read/lines %myfile.txt to read a file and get the single lines. How I am supposed to do this in R3? Thanx Raimund

 [2/11] from: robert:muench:robertmuench at: 14-Feb-2009 11:45


Am 14.02.2009, 11:11 Uhr, schrieb Raimund Dold <raimunddold-web.de>:
> maybe I did not find the answer in the docs, but anyway. > > In R2.0 I regularly used something like read/lines %myfile.txt to read a > file and get the single lines. How I am supposed to do this in R3?
Hi, because R3 supports unicode and unicode can be encoded in different ways, you know have to specify a "format" you want the data to be loaded. Try: deline to-string read %myfile.txt -- Robert M. Münch Mobile: +49 (177) 245 2802 http://www.robertmuench.de

 [3/11] from: Izkata::Comcast::net at: 15-Feb-2009 23:14


Will there be an equivalent in R3 to open/direct/lines %Filename ? On Sat, 2009-02-14 at 11:45 +0100, Robert M. Münch wrote:

 [4/11] from: raimunddold::web::de at: 16-Feb-2009 18:19


Am Samstag 14 Februar 2009 schrieb Robert M. M=FCnch:
> Am 14.02.2009, 11:11 Uhr, schrieb Raimund Dold <raimunddold-web.de>: > > maybe I did not find the answer in the docs, but anyway.
<<quoted lines omitted: 5>>
> Try: > deline to-string read %myfile.txt
Hi, I tried your suggestion but does not provide what I wanted. I have a file lines.txt with the following contents: line 1 line 2 line 3 line 4 line 5 Doing the following in R3:
>> dat: deline to-string read %lines.txt
== {line 1 line 2 line 3 line 4 line 5 }
>> length? dat
== 35 Which shows clearly, that I do not get what read/lines %lines.txt did in R2=2E If I even omit the deline I get the identical results. For me deline seems to be only useful if I get a file from a different platform. Any more suggestions for the read/lines replacement in R3?? Raimund

 [5/11] from: pwawood::gmail::com at: 17-Feb-2009 7:21


Hi Raimund This should work with text:
>> parse/all read %lines.txt newline
== ["line 1" "line 2" "line 3" "line 4" "line 5"] Regards Peter On 17 Feb 2009, at 01:19, Raimund Dold wrote:

 [6/11] from: raimunddold:web at: 18-Feb-2009 19:02


Hi, thanx this works. But also raises another question for me. read %lines.txt returns a binary. Why is it possible to omit the to-string and still get a decent parse result? Is there an implicit to-string? Raimund Am Dienstag 17 Februar 2009 schrieb Peter W A Wood:

 [7/11] from: moliad::gmail at: 18-Feb-2009 14:07


hi Raimund, R2 parses binary data as a string (Although some argue otherwise), you always get string type results. In R2 strings and binary are pretty much the same internally. Its possible the to-string implicit convertion was kept in R3 since, AFAIK, parse hasn't actually been rewritten yet in R3. -MAx On Wed, Feb 18, 2009 at 1:02 PM, Raimund Dold <raimunddold-web.de> wrote:

 [8/11] from: Tom::Conlin::gmail::com at: 18-Feb-2009 11:08


Hi Raimund disclaimer I have not touched R3 yet. R2 parse is not limited to strings, a binary is still a series and parse will accept a series. have you checked that the parsed result is a block of string and not a block of binaries? if so maybe since some binaries are just strings and parse is in string mode when it is splitting on chars not rules the result is allowed to be a string (conjecture) you might try to split a true binary (for example an image file) with a newline and see it the result is a string or binary Raimund Dold wrote:

 [9/11] from: pwawood::gmail::com at: 19-Feb-2009 9:06


Hi Raimund It looks as though parse does an implicit conversion. This is in Rebol Core 2.6.2
>> parse/all to binary! "abcde" [copy inp to end (print type? inp)]
string == true
>> oup: parse/all to binary! "abcde" "c"
== ["ab" "de"]
>> type? first oup
== string!
>> oup: parse/all to binary! "abcde" none
== ["abcde"]
>> type? first oup
== string! and even
>> parse/all #{0000} [copy inp to end (print type? inp)]
string == true At the moment, R3 is slightly different as it seems not to perform the implicit conversion when you supply your own parse rules:
>> parse/all to binary! "abcde" [copy inp to end (print type? inp)]
binary! == true
>> inp
== #{6162636465}
>> oup: parse to binary! "abcde" none
== ["abcde"]
>> type? first oup
== string!
>> oup: parse #{0000} none
== ["^-^-"]
>> type? first oup
== string! Regards Peter On 19 Feb 2009, at 02:02, Raimund Dold wrote:

 [10/11] from: raimunddold:web at: 19-Feb-2009 19:56


Hi, sorry, but it is me again. Your example works for the testfile I provided in the mail but failed on the very next file I tested. The testfile (named testfile.dat) looks like this: =2D---------------------------- St=FCck/Nominale ;"Bezeichnung" 4,636 ;"NAME" =2D---------------------------- Just two lines to get clear results. If I read the file testfile.dat with the following line in R3
>> dat: parse/all read %testfile.dat newline
== ["St=FCck/Nominale" {;"Bezeichnung"} "4,636" {;"NAME"} "" "" "" "" "]
>> length? dat
== 9 Using parenthis around the newline gives even stranger results:
>> dat: parse/all read %testfile.dat {newline}
== [ St=FCck/Nominale" {;"B} "z" "" "ch" "u" {g" 4,636 ;"NAME" }]
>> length? dat
== 7
>> dat/2
== {;"B} Any more suggestions? Raimund Am Dienstag 17 Februar 2009 schrieb Peter W A Wood:

 [11/11] from: pwawood::gmail::com at: 20-Feb-2009 8:05


Hi Raimund On 20 Feb 2009, at 02:56, Raimund Dold wrote:
> Hi, > sorry, but it is me again.
<<quoted lines omitted: 26>>
> Any more suggestions? > Raimund
It seems that your data includes two field separators ";" within a line of text and "newline" at the end of a line of text. You can supply parse with a string of all the separators between your data:
>> parse/all read %testfile.dat join ";" newline
== ["Stock/Nominale" "Bezeichnung" "4,636" "NAME"] In trying this out, it seems that the implicit to binary! conversion in parse does not recognise utf-8 encoding.
>> str: {"St=F6ck/Nominale";"Bezeichnung"}
== {"St=F6ck/Nominale";"Bezeichnung"}
>> write %utest.txt to binary! str
== make port! [ .......
>> to string! read %utest.txt
== {"St=F6ck/Nominale";"Bezeichnung"}
>> parse/all read %utest.txt ";"
== ["St=C3=B6ck/Nominale" "Bezeichnung"] Regards Peter

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted