Re: maps string question

Maria Scott <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <[email protected]>
Hi Nikolas,

> I am loading the data from a file using the file:consult(MapData)
> Currently the file looks like this
> {"key1", {"data1"}}.
> {"key2", {"data2"}}.
> 
> If I want to have all binary for consistency does this means that I need to write into the file as
> {<<"key1">>, {<<"data1">>}}.
> {<<"key2">>, {<<"data2">>}}.

Maybe you should tell us a bit more about what you are trying to do here, in context =^^=

It doesn't really matter whether you are using lists or binaries here, as long as you are using the same to access them in the program.
And however that may be, as the original question was about keys, there is no need to change the values to binaries here, as long as your program handles either lists or binaries or both.

If, by a guess, you are using this file as some sort of config from which you are filling a virgin map, you could just write a map into the file, like #{<<"key1">> => {<<"value1">>}, <<"key2">> => {<<"value2">>}}.

Anyway... no offense, but I get the impression that you don't really know/understand what lists and binaries are? "..." and <<"...">> are not different ways to say string-ish. There are no strings in Erlang. "key1" is just convenient syntactic sugar to write a list of integers, namely [107, 101, 121, 49], and <<"key1">> is just convenient syntactic sugar to write a binary, namely <<107, 101, 121, 49>>.
For an easy-to-graps explanation, you may want to read https://learnyousomeerlang.com/starting-out-for-real#lists and the following paragraphs.

Kind regards,
Maria
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.