Hi, this is my first post, I hope that you are doing well. So I'm just starting erlang, and I have a problem, I'm not sure how to handle it.
So I have a binary that I get in the form
<<56, 23, 67, 34, 45, 78, 01, 54, 67, 87, 45, 53, 01, 34, 56, 78>>
My goal is to split it into an optional list (or binary, if more efficient) based on 01.
For example, the above should look like this:
<<56, 23, 67, 34, 45, 78>> <<54, 67, 87, 45, 53>> <<34, 56, 78>>
-or -
[[56, 23, 67, 34, 45, 78], [54, 67, 87, 45, 53], [34, 56, 78]]
01 is a separation tag; it does not need to be included in the final output.
I tried something like this: (PLEASE neglect if there is a better way)
parse1([]) -> [];
parse1(1) -> io:format("SOHSOHSOHSOHSOHSSOHSOHS");
parse1(Reply) -> parse1({Reply, []});
parse1({Reply, nxtParse}) ->
[H | T] = Reply,
case H of
_ when H > 1 ->
[H | nxtParse],
io:format("Reply 1 = ~p~n", [H]),
parse1({T, nxtParse});
_ when H == 1 ->
io:format("SOHSOHSOHSOHSOHSSOHSOHS");
[] ->
ok
end.
This is not at all clean, and it is not at all like what I am writing about. I am sure that I slammed my head "spirit" when someone tells me.
, , . , ERL BIF -, , .
.
-B