Note that there are some explanatory texts on larger screens.

plurals
  1. POERLANG - Splitting Lists into sub list
    text
    copied!<p>Hi this is my first post here hope you all are well. So Im just starting erlang and I ran into a problem im not sure how to tackle yet. </p> <p>So I have a binary I am recieving in the form of </p> <pre><code>&lt;&lt;56, 23, 67, 34, 45, 78, 01, 54, 67, 87, 45, 53, 01, 34, 56, 78&gt;&gt; </code></pre> <p>My goal is to split it into a sub list (or binary if more efficient) based on the 01.</p> <p>For example the above should come out looking like:</p> <pre><code>&lt;&lt;56, 23, 67, 34, 45, 78&gt;&gt; &lt;&lt;54, 67, 87, 45, 53&gt;&gt; &lt;&lt;34, 56, 78&gt;&gt; </code></pre> <p>-or-</p> <pre><code>[[56, 23, 67, 34, 45, 78], [54, 67, 87, 45, 53], [34, 56, 78]] </code></pre> <p>The 01 is the separating tag, it does not need to be included in the final output.</p> <p>I have tried something as such: (PLEASE disregard if there is a better way)</p> <pre><code>parse1([]) -&gt; []; parse1(1) -&gt; io:format("SOHSOHSOHSOHSOHSSOHSOHS"); parse1(Reply) -&gt; parse1({Reply, []}); parse1({Reply, nxtParse}) -&gt; [H | T] = Reply, case H of _ when H &gt; 1 -&gt; [H | nxtParse], io:format("Reply 1 = ~p~n", [H]), parse1({T, nxtParse}); _ when H == 1 -&gt; io:format("SOHSOHSOHSOHSOHSSOHSOHS"); [] -&gt; ok end. </code></pre> <p>This isn't really clean at all and doesn't resemble at all what pro's write. Im sure Ill smack my head "duh" when someone clues me in.</p> <p>I realize there is definitely more than one solution, but what is the BEST one. It seems ERL has so many BIF's and way to do things, just gotta find my way around I guess.</p> <p>Thanks for the help guys -B</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload