[erlang-questions] How to pass the length of binary to match into a function that matches the binary?
Mon Nov 24 15:53:45 CET 2014
On 24 Nov 2014, at 13:26, Ulf Wiger <> wrote:
> On 24 Nov 2014, at 13:56, Russell Brown <> wrote:
>> Is there a way to do this:
>> my_fun(Bin, Len, <<Bin:Len/binary, Rest/binary>>) ->
>> %% do stuff with Bin
>> Len is unbound is the reason I can’t, but it seems like the sort of thing that would be useful if I could.
> Yes, it’s slightly unfortunate, but you can write:
> my_fun(B, Len, Binary) ->
> case Binary of
> <<B:Len/binary, Rest/binary>> ->
> %% do stuff with B
This is what I went with. Thanks Ulf
> Ulf W
> Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
More information about the erlang-questions