- -module(change).
- -compile(export_all).
- start()->
- ets:new(sort_me,[named_table,public,bag]),
- spawn(fun()->
- a(),
- b()
- end).
-
- a()->
- {ok,R}=file:read_file("a.txt"),
- P=binary:split(R,<<"\r\n">>,[global]),
- Z=fun(Q)->[H|_]=re:split(Q,<<"\s+">>),binary_to_list(H) end,
- [ ets:insert(sort_me,{Z(Q),binary_to_list(Q)}) || Q <- P ].
-
- b()->
- {ok,F}=file:open("b.txt",read),
- w(F).
- w(X)->
- case io:get_line(X,'') of
- eof -> ok;
- A ->
- B=re:replace(A,"\n|\t","",[global,{return,list}]),
- ets:lookup(sort_me,"ttt"),
- Xx=ets:lookup(sort_me,B),
- io:format("~p => ~p~n",[B,Xx]),
- w(X)
- end.
-
- r(F)->
- {ok,G}=file:read_file(F),
- G.
复制代码 |