[erlang-questions] file:read_line - conflicting return values' syntax - no case clause matching eof exception
Richard O'Keefe
ok@REDACTED
Tue Feb 16 00:21:12 CET 2010
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.
>
What ambiguity?
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}.
>
>
>
More information about the erlang-questions
mailing list