What is the idiomatic way of doing...

Vladimir Sekissov svg@REDACTED
Thu Apr 10 12:11:00 CEST 2003


Good day,

hp> Suppose test.txt is very big and it is better to extract one tuple at a
hp> time to do something.
hp> (1) what is the erlang-way of doing this ???

26> {ok, IO} = file:open("tmp.txt", [read]).
{ok,<0.90.0>}
27> io:read(IO, "").
{ok,{"label1","v1"}}
28> io:read(IO, "").
{ok,{"label2","v2"}}
29> io:read(IO, "").
eof
30> file:close(IO).
ok

hp> Suppose I have this file:
hp> % test1.txt content
hp> label1    v1
hp> label2    v2
hp> 
hp> (2) Is there an idiomatic way of getting the list of tuples as in the
hp>     previous case ??

39> {ok, IO} = file:open("/home/svg/tmp.txt", [read]).
{ok,<0.109.0>}
40> list_to_tuple(string:tokens(io:get_line(IO, ""), " \t\n")).
{"label1","v1"}
...

Best Regards,
Vladimir Sekissov

hp>   Three newbie questions:
hp> 
hp> Suppose I have a file:
hp> % test.txt content
hp> {"label1", "v1"}.
hp> {"label2", "v2"}.
hp> 
hp> In erl, file:consult(test.txt) will give me a list of
hp> tuples  [{"label1","v1"},{"label2","v2"}].
hp> 
hp> Suppose test.txt is very big and it is better to extract one tuple at a
hp> time to do something.
hp> (1) what is the erlang-way of doing this ???
hp> 
hp> ---------------------------------------
hp> Suppose I have this file:
hp> % test1.txt content
hp> label1    v1
hp> label2    v2
hp> 
hp> (2) Is there an idiomatic way of getting the list of tuples as in the
hp>     previous case ??
hp> 
hp> (3) What about getting one tuple at a time ???
hp> 
hp> THanks,
hp> HP
hp> 



More information about the erlang-questions mailing list