[erlang-questions] Binary:split and re:split woes

Robert Virding robert.virding@REDACTED
Thu Dec 5 13:41:44 CET 2013


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?

Robert

----- 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 or
> 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 for
> bad behaviour.
> 
> Sigh,
> Robert
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
> 



More information about the erlang-questions mailing list