[erlang-questions] binary strings and interspersing erlang variables

Lukas Larsson <>
Fri Mar 9 23:57:50 CET 2012


You might want to consider creating a iolist, i.e.
[<<"html">>,Port,<<"</html>">>].

Most if not all output interfaces allow you to mix lists and binaries
like this. This makes it more elegant to generate complex structures
(imo) and possibly faster as well as you do not combine the binaries
until just before sending it over the socket.

Lukas

On Fri, Mar 9, 2012 at 11:37 PM, Wes James <> wrote:
> I'm working with binary data like this:
>
> <<"<html>
> <head>
> <script>
> </script>
> </head>
> <body>
> </body>
> </html>">>
>
> I then set
>
> Port= <<"8080">>;
>
> and now to put Port in to the html code above:
>
> <<<<"<html>
> <head>
> <script>
> port='">>/binary,
> Port/binary,
> <<"';
> </script>
> </head>
> <body>
> </body>
> </html>">>/binary>>
>
> Is there a better way to do this?
>
> Thanks,
>
> Wes
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list