Pregunta

I have the following property list

PropList = [{numbers, ["22", "10"]}, {etc, "22"}].

I wish to get out the list ["22", "10"] like this:

proplists:get_value(numbers, PropList).

The problem is that I get the two strings inside the list concatenated, ie "2210". I tried using propertylists:lookup/2 to get the whole numbers tuple and pattern match to extract the list. But I still end up getting "2210".

I'm guessing it's because of the way erlang stores strings in memory.. Can someone help me here?

Later Edit: I've managed to extract and use the data if i do a map over the list of strings... Maybe this is just a printing issue?

Later-Later Edit I don't know what happened, maybe I'm too tired :) sorry guys. Will delete this question tomorrow

¿Fue útil?

Solución

1> PropList = [{numbers, ["22", "10"]}, {etc, "22"}].       
[{numbers,["22","10"]},{etc,"22"}]

2> proplists:get_value(numbers, PropList).
["22","10"]

3> 

That is my output with your given snippet.

Otros consejos

Yes, the code is correct. If you use io:format, it will concatenate all it can on output.

There is a meta-type in Erlang called iolist as in "can be used for input/output". It can be a list of characters (integers), other iolists or a binary. Sounds confusing, but quite handy.

If you want to pretty-print, use the ~p format.

In other words:

2> io:format([[65, $B, 67], <<"DEF">>, [[71, 72], 73], "JKL", 10]).
ABCDEFGHIJKL
ok
3> io:format("~p", [[[65, $B, 67], <<"DEF">>, [[71, 72], 73], "JKL", 10]]).
["ABC",<<"DEF">>,["GH",73],"JKL",10]ok
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top