KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
What is the most efficient way from the time consumed to read a text file into a list of binary strings in erlang ? The obvious solution -module(test). -export([run/1]). open_file(FileName, Mode) -> {ok, Device} = file:open(FileName, [Mode, binary]), Device. close_file(Device) -> ok = file:close(Device). read_lines(Device, L) -> case io:get_line(Device, L) of eof -> lists:reverse(L); String -> read_lines(Device, [String | L]) end. run(InputFileName) -> Device = open_file(InputFileName, read), Data = read_lines(Device, []), close_file(Device), io:format("Read ~p lines~n", [length(Data)]). becomes too slow when the file contains more than 100000 lines.
Tags (comma-separated)
Save Edits
Cancel