How to match on a nested record against a dict

Jarrod Roberson jarrod@REDACTED
Sun Nov 22 06:52:21 CET 2009


I have the following data structure: it is a record as specified in
inet_dns.hrl:

{ok,{dns_rec,{dns_header,0,true,'query',true,false,false,false,false,0},
                   [],
                   [{dns_rr,"_see._tcp.local",ptr,in,0,0,
                            "jhr@REDACTED",undefined,[],
                            false}],
                   [],[]}}

I have the following code where Sub is a dict:

receiver(Sub) ->
    receive
        {udp, _Socket, IP, InPortNo, Packet} ->
            DnsRec = inet_dns:decode(Packet),
               io:format("~n~nFrom: ~p~nPort: ~p~nData:
~p~n",[IP,InPortNo,DnsRec]),
               receiver(Sub);
           stop ->
               true;
         AnythingElse ->
               %io:format("RECEIVED: ~p~n",[AnythingElse]),
               receiver(Sub)
       end.

I want to match on the "_see._tcp.local" and see if it is in the dns_rr
record and only do the io:format() if that is in my subscriptions dict.
Can anyone point me in the right direction of what idiom to use? This
pattern matching stuff is difficult for us olde school if () ers


More information about the erlang-questions mailing list