[erlang-questions] BIF for writing logs

Bob Ippolito bob@REDACTED
Thu Jan 20 09:32:16 CET 2011


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


More information about the erlang-questions mailing list