<div>
Hi,
</div><div><br></div><div>I've got a binary split that I'm doing fairly regularly, so I wanted to use a compiled pattern to make it more efficient. I don't have any state floating around (it's very much a utility function), so my plan was to compile the pattern in an erl shell and just paste the resultant term directly into my source code (with an appropriate comment!). However, things are not as they seem:</div><div><br></div><div><div><font face="Courier New">Erlang R15B02 (erts-5.9.2) [source] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">Eshell V5.9.2 (abort with ^G)</font></div><div><font face="Courier New">1> C = binary:compile_pattern(<<0,0,1,0>>).</font></div><div><font face="Courier New">{bm,<<>>}</font></div><div><font face="Courier New">2> X = <<2,3,4,0,0,1,0,5,6,7>>.</font></div><div><font face="Courier New"><<2,3,4,0,0,1,0,5,6,7>></font></div><div><font face="Courier New">3> binary:split(X, C).</font></div><div><font face="Courier New">[<<2,3,4>>,<<5,6,7>>]</font></div><div><font face="Courier New">4> binary:split(X, {bm,<<>>}).</font></div><div><font face="Courier New">** exception error: bad argument</font></div><div><font face="Courier New"> in function binary:split/3 (binary.erl, line 84)</font></div><div><font face="Courier New">5> D = binary_to_term(term_to_binary(C)).</font></div><div><font face="Courier New">{bm,<<>>}</font></div><div><font face="Courier New">6> C = D.</font></div><div><font face="Courier New">{bm,<<>>}</font></div><div><font face="Courier New">7> D =:= C.</font></div><div><font face="Courier New">true</font></div><div><font face="Courier New">8> binary:split(X, D).</font></div><div><font face="Courier New">** exception error: bad argument</font></div><div><font face="Courier New"> in function binary:split/3 (binary.erl, line 84)</font></div><div><font face="Courier New">9> </font></div></div><div><br></div><div>The above should be fairly self-explanatory - I'm very confused and either being particularly dim tonight, or there is some dark magic at work :) Can anyone shed any light?</div><div><br></div><div>Cheers,</div><div><br></div><div>Steve</div>
<div><div><br></div><div>-- </div><div>Steve Strong</div><div>Sent with <a href="http://www.sparrowmailapp.com/?sig">Sparrow</a></div><div><br></div></div>