[erlang-questions] constructing binaries question
Thu Sep 14 22:01:36 CEST 2006
> I'm writing some code to construct a binary SQL statement from some
> parameters (table name, field names, field values, etc). I'm not sure
> if I should iteratively add more chunks to a binary representing the
> statement, or if I should build the statement from a list of strings
> and then call list_to_binary at the end. What's the rule of thumb for
> working with binaries as opposed to lists in such a scenario?
It depends on what you want to do with it. Most of the io functions
understands lists of binaries. That being the case I usually just
build up a list of binaries and give it directly to the io function.
If you are passing the binaries around in your function then a list of
binaries may not be a good choice, because it makes pattern matching
the binary much more difficult (you don't know where the boundaries of
each piece are so you can't assume a contiguous binary for matching).
More information about the erlang-questions