[erlang-questions] BIF for writing logs
Alain O'Dea
alain.odea@REDACTED
Thu Jan 20 13:11:40 CET 2011
On 2011-01-20, at 5:02, Bob Ippolito <bob@REDACTED> wrote:
> On Thu, Jan 20, 2011 at 4:22 PM, maruthavanan s
> <maruthavanan_s@REDACTED> wrote:
>>
>> Hi,Do we have any module or function that would return string to me what ever I give as input like below.M:F(atom) should return "atom"M:F(9999) should return "9999"M:F("string") should return "string"M:F({tuple}) should return "{tuple}"M:F([1,2,3]) should return "[1,2,3]"I am asking this because I would like to write use this function to write the return values in a file.Thanks,Marutha
> io_lib:format/2. Not a BIF.
>
> 1> io_lib:format("~p", [{tuple}]).
> [[123,["tuple"],125]]
> 2> lists:flatten(io_lib:format("~p", [{tuple}])).
> "{tuple}"
>
> If you're writing it to a file, you should just use the output iolist
> directly (as shown in 1), because it will be more efficient. The
> second example is just to show equivalence.
>
> -bob
You can also use ~w instead if you don't need nicely indented output files:
io_lib:format("~w", [{tuple}]).
An even leaner approach is the binary external format. IMHO, it should be used unless you need human readable files:
http://www.erlang.org/doc/apps/erts/erl_ext_dist.html
term_to_binary/1,2
binary_to_term/1
More information about the erlang-questions
mailing list