Erlang错误:没有与io:请求匹配的函数子句

Erlang错误:没有与io:请求匹配的函数子句,erlang,Erlang,我是一名新加入Erlang的经验丰富的程序员,我被以下几点困住了: myread() -> {_, MyData } = file:read_file( "hands.txt" ), io:format( "hands-out.txt", "~w", MyData ). 从shell调用myread()时产生: ** exception error: no function clause matching io:request("hands-out.txt",

我是一名新加入Erlang的经验丰富的程序员,我被以下几点困住了:

myread() ->
    {_, MyData } = file:read_file( "hands.txt" ),
    io:format( "hands-out.txt", "~w", MyData ).
从shell调用myread()时产生:

** exception error: no function clause matching io:request("hands-out.txt",
          {format,"~w", <<"3h 5h 7h 8h 3h 5h 7h 8h q"...>>}) 
      (io.erl, line 556)  in function  io:o_request/3 (io.erl, line 63)
**异常错误:没有与io:request(“hands out.txt”)匹配的函数子句,
{格式,“~w”,})
(io.erl,第556行)在功能io:o_请求/3(io.erl,第63行)中
任何帮助都将不胜感激。

两件事:

“hands-out.txt”,“~w”
需要是一个字符串:
“hands-out.txt:~w”

替换
~w
的数据需要是一个列表。因此:

io:format(“hands-out.txt:~w”,[MyData])。

此外,您还应该在从
文件:read_file/1
返回的状态值上进行模式匹配。在您的版本中,返回为
{error,Reason}
的错误将在此处匹配,因为您使用的是
\uuu
,并且您将打印错误原因而不是文件,这可能会造成混淆

因此,如果您想在读取错误时崩溃,请将其设置为
{ok,MyData}=file:read_file(“hands.txt”)
,如果您想处理这种情况,请执行以下操作:

myread() ->
  case file:read_file( "hands.txt" ) of
    {ok, MyData } ->
      io:format( "hands-out.txt: ~w", [MyData] );
    {error, Error} ->
      io:format("Error: ~w~n", [Error])
  end.
两件事:

“hands-out.txt”,“~w”
需要是一个字符串:
“hands-out.txt:~w”

替换
~w
的数据需要是一个列表。因此:

io:format(“hands-out.txt:~w”,[MyData])。

此外,您还应该在从
文件:read_file/1
返回的状态值上进行模式匹配。在您的版本中,返回为
{error,Reason}
的错误将在此处匹配,因为您使用的是
\uuu
,并且您将打印错误原因而不是文件,这可能会造成混淆

因此,如果您想在读取错误时崩溃,请将其设置为
{ok,MyData}=file:read_file(“hands.txt”)
,如果您想处理这种情况,请执行以下操作:

myread() ->
  case file:read_file( "hands.txt" ) of
    {ok, MyData } ->
      io:format( "hands-out.txt: ~w", [MyData] );
    {error, Error} ->
      io:format("Error: ~w~n", [Error])
  end.