我正在尝试从文本文件中读取数据,将文件中的元组放入列表中,然后将其映射,代码如下所示。我是erlang的新手,也不知道我在做什么错:
-module(exchange).
-export([start/0]).
start()->
A= file:consult("calls.txt"),
B=tuple_to_list(A),
io:fwrite("~p~n",[maps:from_list([B])]).
它给了我错误:
5> c(exchange).
{ok,exchange}
26> exchange:start().
** exception error: bad argument
in function maps:from_list/1
called as maps:from_list([[ok,
[{john,[jill,joe,bob]},
{jill,[bob,joe,bob]},
{sue,[jill,jill,jill,bob,jill]},
{bob,[john]},
{joe,[sue]}]]])
in call from exchange:start/0 (exchange.erl, line 10)
请在这里帮助我。谢谢。
答案 0 :(得分:0)
file:consult/2
成功返回{ok, Terms}
,这样就可以了:
{ok, A} = file:consult("calls.txt"),
io:fwrite("~p~n", [maps:from_list(A)]).