|
As per the documentation here -
http://ftp.sunet.se/pub/lang/erlang/doc/man/file.html#read_line-1 , the syntax reads as - read_line(IoDevice) -> {ok, Data} | eof | {error, Reason} Given the ambiguity in the return values of the function , I am unsure how to handle it. do_read_file(IoDevice, InData, Accum) -> case file:read_line(IoDevice) of {'ok', Data} -> do_read_file(IoDevice, Data, lists:append(Accum, InData)); { 'eof' } -> Accum end. I wrote this function to use the same, but I am getting - "** exception error: no case clause matching eof" . What is the best way to handle the same ? |
|
On Sun, Feb 14, 2010 at 11:59:31PM -0800, Kay Kay wrote:
> As per the documentation here - > > http://ftp.sunet.se/pub/lang/erlang/doc/man/file.html#read_line-1 , > the syntax reads as - > > read_line(IoDevice) -> {ok, Data} | eof | {error, Reason} > > Given the ambiguity in the return values of the function , I am unsure > how to handle it. > > > > do_read_file(IoDevice, InData, Accum) -> > case file:read_line(IoDevice) of > {'ok', Data} -> > do_read_file(IoDevice, Data, lists:append(Accum, InData)); > { 'eof' } -> > Accum > end. > > > I wrote this function to use the same, but I am getting - "** exception > error: no case clause matching eof" . > > What is the best way to handle the same ? Note that eof is not a tuple (which is the general case when using a single atom), so check the single atom eof in a clause case ... {ok, Data} -> ... eof -> ... {error, Err} -> ... end ~M > > ________________________________________________________________ erlang-questions (at) erlang.org mailing list. See http://www.erlang.org/faq.html To unsubscribe; mailto:[hidden email] |
|
In reply to this post by Kay Kay-2-3
Kay Kay wrote:
> As per the documentation here - > > http://ftp.sunet.se/pub/lang/erlang/doc/man/file.html#read_line-1 , > the syntax reads as - > > read_line(IoDevice) -> {ok, Data} | eof | {error, Reason} > > Given the ambiguity in the return values of the function , I am unsure > how to handle it. Ambiguity? Which ambiguity? The return values {ok, Data} and {error, Reason} are pairs (2-tuples) which are distinguished by a different atom in the 1st position. The third return value is an *atom*. Do not wrap it in { } and make it a one-element tuple instead... Kostis > do_read_file(IoDevice, InData, Accum) -> > case file:read_line(IoDevice) of > {'ok', Data} -> > do_read_file(IoDevice, Data, lists:append(Accum, InData)); > { 'eof' } -> > Accum > end. > > > I wrote this function to use the same, but I am getting - "** exception > error: no case clause matching eof" . > > What is the best way to handle the same ? ________________________________________________________________ erlang-questions (at) erlang.org mailing list. See http://www.erlang.org/faq.html To unsubscribe; mailto:[hidden email] |
|
In reply to this post by Kay Kay-2-3
On Feb 15, 2010, at 8:59 PM, Kay Kay wrote: > As per the documentation here - > > http://ftp.sunet.se/pub/lang/erlang/doc/man/file.html#read_line-1 , > the syntax reads as - > > read_line(IoDevice) -> {ok, Data} | eof | {error, Reason} > > Given the ambiguity in the return values of the function , I am > unsure how to handle it. > All goes well: you get {ok,Data}. Normal end of file: you get eof. Some problem: you get {error,Reason}. > > > do_read_file(IoDevice, InData, Accum) -> > case file:read_line(IoDevice) of > {'ok', Data} -> > do_read_file(IoDevice, Data, lists:append(Accum, InData)); > { 'eof' } -> --------- The description says eof, not {eof}. > > Accum > end. > > > I wrote this function to use the same, but I am getting - "** > exception error: no case clause matching eof" . > > What is the best way to handle the same ? By writing a pattern that matches eof, not {eof}. > > > ________________________________________________________________ erlang-questions (at) erlang.org mailing list. See http://www.erlang.org/faq.html To unsubscribe; mailto:[hidden email] |
| Powered by Nabble | Edit this page |
