[erlang-questions] List matching, help me make this look better
Steve Vinoski
vinoski@REDACTED
Sat Apr 25 20:01:16 CEST 2009
On 4/25/09, Kevin <q2h46uw02@REDACTED> wrote:
>
> As an example I want to read a file, line by line, and pass the line
> into a function, and it want it to match
> on the first 4 characters. In the example I'm matching on "aaaa",
> "bbbb", "cccc".
See Kostis's reply for the answer, but I just wanted to comment on the
following:
> I also tried converting everything to binaries but that traded ugly for
> ugly.
Not sure why you'd call the binary approach ugly -- just rewriting
your example a bit yields:
myfunc(<<"aaaa", _/binary>>) ->
io:format("matched aaaa~n");
myfunc(<<"bbbb", _/binary>>) ->
io:format("matched bbbb~n");
myfunc(<<"cccc", _/binary>>) ->
io:format("matched cccc~n");
myfunc(_) ->
io:format("no matches~n").
--steve
More information about the erlang-questions
mailing list