[erlang-questions] How to pass the length of binary to match into a function that matches the binary?
Mon Nov 24 14:26:26 CET 2014
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
Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 496 bytes
Desc: Message signed with OpenPGP using GPGMail
More information about the erlang-questions