我试图在 ETS 中插入一个列表以便稍后退出,并且由于某种原因它说这是一个错误的参数。我不确定我是否插入不正确。
是不是不可能在 ETS 中插入一个列表?
违规行是ets:insert(table, [{parsed_file, UUIDs}])
.
这是代码:
readUUID(Id, Props) ->
fun () ->
%%TableBool = proplists:get_value(table_bool, Props, <<"">>),
[{_, Parsed}] = ets:lookup(table, parsed_bool),
case Parsed of
true ->
{uuids, UUIDs} = ets:lookup(table, parsed_bool),
Index = random:uniform(length(UUIDs)),
list_to_binary(lists:nth(Index, UUIDs));
false ->
[{_, Dir}] = ets:lookup(table, config_dir),
File = proplists:get_value(uuid_file, Props, <<"">>),
UUIDs = parse_file(filename:join([Dir, "config", File])),
ets:insert(table, [{parsed_file, {uuids, UUIDs}}]),
ets:insert(table, [{parsed_bool, true}]),
Index = random:uniform(length(UUIDs)),
list_to_binary(lists:nth(Index, UUIDs))
end
end.
parse_file(File) ->
{ok, Data} = file:read_file(File),
parse(Data, []).
parse([], Done) ->
lists:reverse(Done);
parse(Data, Done) ->
{Line, Rest} = case re:split(Data, "\n", [{return, list}, {parts, 2}]) of
[L,R] -> {L,R};
[L] -> {L,[]}
end,
parse(Rest, [Line|Done]).