[erlang-questions] Binary:split and re:split woes
Thu Dec 5 14:09:30 CET 2013
In section 4.1: A *sub binary* is created by split_binary/2 and when a
binary is matched out in a binary pattern. A sub binary is a reference into
a part of another binary (refc or heap binary, never into a another sub
binary). Therefore, matching out a binary is relatively cheap because the
actual binary data is never copied.
So hopefully it is cheap. I also hate the beginning <<>>, so annoying. I
have code in tons of places that removes it.
On Thu, Dec 5, 2013 at 1:41 PM, Robert Virding <
> A follow up question is whether and when the splits create new binaries.
> So if the input to split is a binary and the outputs are also binary are
> they completely new binaries or just references into the old binary sharing
> the actual binary data?
> ----- Original Message -----
> > From: "Robert Virding" <robert.virding@REDACTED>
> > These two functions allow you give a pattern to split binaries (and
> lists in
> > re) into a list of sub binaries. If the split pattern occurs at the
> > beginning or end of the binary then you get empty parts at the beginning
> > end. So:
> > binary:split(<<" abc def ghi ">>, <<" ">>, [global]) ==>
> > [<<>>,<<"abc">>,<<"def">>,<<"ghi">>,<<>>]
> > This is fine and logical. Often you don't want these empty parts so
> there is
> > a 'trim' options which removes them. But it only trims at the end and
> not at
> > the beginning. So:
> > binary:split(<<" abc def ghi ">>, <<" ">>, [global,trim]) ==>
> > [<<>>,<<"abc">>,<<"def">>,<<"ghi">>]
> > This is stupid! Saying it it done like this Perl is hardly a good excuse
> > bad behaviour.
> > Sigh,
> > Robert
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions