[erlang-questions] Using File containing list as an input

Joe Armstrong erlang@REDACTED
Sun Jul 1 18:22:04 CEST 2018


I'll do this with a 4 element list to show the principle (you have a
100K list but it works the same way)

1> L = [1234,45,67,89].
[1234,45,67,89]
2> file:write_file("foo", term_to_binary(L)).
ok
3> {ok, B} = file:read_file("foo").
{ok,<<131,108,0,0,0,4,98,0,0,4,210,97,45,97,67,97,89,106>>}
4> binary_to_term(B).
[1234,45,67,89]

term_to_binary turns anything into a binary which you save in a file
binary_to_term is the inverse

Cheers

/Joe


On Sun, Jul 1, 2018 at 3:14 PM, Awsaf Rahman <awsafrahman1704@REDACTED> wrote:
> Hello! I am new to Erlang and need some help!
>
> I generated a random list of 100,000 numbers and wrote them in a file. Now I
> want to use that list in the file as an input for different programs. What I
> am trying to do is benchmark some programs written in Erlang like Merge Sort
> and I want to use the same list in different variations of the program. If
> anyone can help me out it would be of big help!
>
> Thanks!
>
> Regards
>
> Awsaf Rahman
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list