Re: Write Term to File
Michał Muskała <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <DB7PR07MB3899729D01C972D621EFD9FCFABC0@DB7PR07MB3899.eurprd07.prod.outlook.com> |
Those two values are exactly the same. Lists of integers representing codepoints and strings are two ways of representing the same value. Reading back with file:consult should reproduce exactly the same values.
$ erl
Erlang/OTP 23 [erts-11.1.5] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [hipe] [dtrace]
Eshell V11.1.5 (abort with ^G)
1> {"cn",[28450]} =:= {"cn","漢"}.
true
2> io:format("~tp.\n",[{"cn","漢"}]).
{"cn",[28450]}.
ok
If you’re asking if you can make io:format print the string representation rather than list one for high-codepoint characters, the answer is you can, by starting the VM in Unicode mode with +pc unicode flag:
$ erl +pc unicode
Erlang/OTP 23 [erts-11.1.5] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [hipe] [dtrace]
Eshell V11.1.5 (abort with ^G)
1> io:format("~tp.\n",[{"cn","漢"}]).
{"cn","漢"}.
ok
Michał.
From: erlang-questions <[email protected]> on behalf of Oliver Bollmann <[email protected]>
Date: Tuesday, 26 January 2021 at 22:52
To: Erlang-Questions Questions <[email protected]>
Subject: Write Term to File
How can i write term to file, for later using in file:consult?
I do:
R = io_lib:format("~tp.",[{"cn","漢"}]),
file:write_file(FileName,R)
But this gives:
{"cn",[28450]}.
I need:
{"cn","漢"}.
Any hints?
--
Grüße
Oliver Bollmann