[erlang-questions] CSV file help

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Mon Nov 12 13:30:40 CET 2012


On Nov 12, 2012, at 8:54 AM, Lucky Khoza <mrkhoza@REDACTED> wrote:

> Hi Erlang Developers,
> 
> Where do i start in terms of reading CSV file, because i tried to use this rountines:
> 
> {ok,String} = file:open("produce.csv",read).
> io:get_line(String, ' ').

There are two problems here:

first, file:open/2 should be called appropriately and Bengt writes. Second, the binding {ok, String} should rather be {ok, IoDevice} in order to be more precise. The IO device needs to be used to read out data from the file in question. Look at the call file:read_line/2.

The io:get_line/2 call is probably ok, but I would prefer file:read_line/2 since it does not have to be given a prompt. Speaking of prompt, the value '' is not a string but an (empty) atom. In Erlang, you can't interchange ' and " like many other languages (almost) allows you to.

The {error, terminated} is probably because your IoDevice was not opened correctly and thus the call fails. 

Jesper Louis Andersen
  Erlang Solutions Ltd., Copenhagen






More information about the erlang-questions mailing list