I need to put data in a file since my other function takes a file as input.
How to I create a uniq filename in Erlang?
Something like unix "tempfile", do it exist?
I need to put data in a file since my other function takes a file as input.
How to I create a uniq filename in Erlang?
Something like unix "tempfile", do it exist?
Do you mean just generate the acutal filename? In that case the safest way would be to use a mix of the numbers you get from now() and the hostname of your computer (if you have several nodes doing the same thing).
Something like:
1> {A,B,C}=now().
{1249,304278,322000}
2> N=node().
nonode@nohost
3> lists:flatten(io_lib:format("~p-~p.~p.~p",[N,A,B,C])).
"[email protected]"
4>
Or you could do
erlang:phash2(make_ref())
for a quick and easy unique indentifier. Unique for up to 2^82 calls which should be enough.for your purposes. I find this easier than formatting a timestamp with node name for use.
Late answer: I just noticed the test_server module which has scratch directory support, worth a look
http://erldocs.com/otp%5Fsrc%5FR13B/test%5Fserver/test%5Fserver.html?i=12