[erlang-questions] How to match on a nested record against a dict

Jarrod Roberson <>
Tue Nov 24 21:18:06 CET 2009


Thanks for the example code, it is getting me past the "how" and onto the
"why" of logic in Erlang, I have it all working except this one part. I keep
getting this exception. I have used your example and come up with this.

start() ->
   S=open({224,0,0,251},5353),

Pid=spawn(?MODULE,receiver,[dict:store("_see._tcp.local",[],dict:new())]),
   gen_udp:controlling_process(S,Pid),
   {S,Pid}.

receiver(Sub) ->
  receive
      {udp, _Socket, _IP, _InPortNo, Packet} ->
          process_dnsrec(Sub,inet_dns:decode(Packet)),
          receiver(Sub);
       stop ->
           true;
       AnythingElse ->
           io:format("RECEIVED: ~p~n",[AnythingElse]),
           receiver(Sub)
   end.

process_dnsrec(_Sub,{error,E}) -> io:format("Error: ~p~n", [E]);
process_dnsrec(Sub,{ok,#dns_rec{anlist=Responses}}) ->
process_dnsrec1(Sub,Responses).

process_dnsrec1(_,[]) -> ok;
process_dnsrec1(Sub,[#dns_rr{domain=Dom}|Rest]) ->
  case dict:find(Dom,Sub) of
      [Result] ->
          io:format("Interesting domain ~p=~p~n",[Dom,Result]);
     error ->
          %% do nothing for non-interesting domains
         ok
  end,
  process_dnsrec1(Sub,Rest).

and here is the Error I am getting

Erlang R13B02 (erts-5.7.3) [source] [smp:2:2] [rq:2] [async-threads:0]
[kernel-poll:false]

Eshell V5.7.3  (abort with ^G)
1> zeroconf:start().
{#Port<0.442>,<0.34.0>}
2>
=ERROR REPORT==== 24-Nov-2009::15:16:40 ===
Error in process <0.34.0> with exit value:
{{case_clause,{ok,[]}},[{zeroconf,process_dnsrec1,2},{zeroconf,receiver,1}]}


More information about the erlang-questions mailing list