Using File containing list as an input

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using File containing list as an input

Awsaf Rahman

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
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Using File containing list as an input

Karlo Kuna
i think file:consult/1 (http://erlang.org/doc/man/file.html#consult-1) could be good for your usecase. 


On Sun, Jul 1, 2018 at 3:58 PM Awsaf Rahman <[hidden email]> 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
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Using File containing list as an input

Joe Armstrong-2
In reply to this post by Awsaf Rahman
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 <[hidden email]> 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
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions