[erlang-questions] file:read_line - conflicting return values' syntax - no case clause matching eof exception

Michael McDaniel erlangy@REDACTED
Mon Feb 15 09:22:40 CET 2010


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



>
>


More information about the erlang-questions mailing list