Alexander Shavelev
Alexander Shavelev

Reputation: 324

illegal bit size in pattern matching

i have field and must check that it have such view <<"{{name_of_field}}">>

i make

try
    <<"{{", _/binary>> = FieldName
  catch
    _:_ ->
      throw(error)
  end,
  Size = byte_size(FieldName),
  try
    <<_:(Size-2)/binary, "}}">> = FieldName
  catch
    _:_ ->
      throw(error)
  end

and get "* 1: illegal bit size" when match Tail of FieldName

Upvotes: 0

Views: 337

Answers (1)

Alexander Shavelev
Alexander Shavelev

Reputation: 324

looks good i've find solution

The expression (Size-2) is supported when constructing a binary. This is definitely a pattern matching, so as stated above: the Size must be a constant expression or a variable. Not an expression to be evaluated at runtime.

all answer http://erlang.org/pipermail/erlang-questions/2012-December/071145.html

Upvotes: 2

Related Questions