The group you are posting to is a
Usenet group . Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
From:
Lucky Khoza <mrkh... @gmail.com>
Date: Mon, 12 Nov 2012 09:54:25 +0200
Local: Mon, Nov 12 2012 2:54 am
Subject: [erlang-questions] CSV file help
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, ' ').
but when i used this rountine: io:get_line(String,' ') to read each line i
got this tuple: {error,terminated},
And the file i'm trying to read is like this:
"Supplier ID","Product Code","Product Description","Delivery Date","Unit
Price","Number of Units"
15,1101,"Apples 1kg Golden Delicious. The sweetest Apples! Always a
favourite. Love, Mrs. Hollingberry","2012/02/15",1505,5
Thanks in advance for your help.
Kindest Regards
Lucky
_______________________________________________
erlang-questions mailing list
erlang-questi... @erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Bengt Kleberg <bengt.kleb... @ericsson.com>
Date: Mon, 12 Nov 2012 09:04:52 +0100
Local: Mon, Nov 12 2012 3:04 am
Subject: Re: [erlang-questions] CSV file help
Greetings,
The documentation page for io:file/2 says that the second argument
should be a list of atoms. Like this: [read].
If {ok, String} matches, then you are probably just lucky.
bengt
On Mon, 2012-11-12 at 09:54 +0200, Lucky Khoza 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, ' ').
> but when i used this rountine: io:get_line(String,' ') to read each
> line i got this tuple: {error,terminated},
> And the file i'm trying to read is like this:
> "Supplier ID","Product Code","Product Description","Delivery
> Date","Unit Price","Number of Units"
> 15,1101,"Apples 1kg Golden Delicious. The sweetest Apples! Always a
> favourite. Love, Mrs. Hollingberry","2012/02/15",1505,5
> Thanks in advance for your help.
> Kindest Regards
> Lucky
> _______________________________________________
> erlang-questions mailing list
> erlang-questi... @erlang.org
> http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
erlang-questi... @erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Michael Uvarov <free... @gmail.com>
Date: Mon, 12 Nov 2012 15:20:16 +0300
Local: Mon, Nov 12 2012 7:20 am
Subject: Re: [erlang-questions] CSV file help
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Jesper Louis Andersen <jesper.louis.ander... @erlang-solutions.com>
Date: Mon, 12 Nov 2012 13:30:40 +0100
Local: Mon, Nov 12 2012 7:30 am
Subject: Re: [erlang-questions] CSV file help
On Nov 12, 2012, at 8:54 AM, Lucky Khoza <mrkh... @gmail.com> 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
_______________________________________________
erlang-questions mailing list
erlang-questi... @erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
You must
Sign in before you can post messages.
You do not have the permission required to post.