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

Igor Ribeiro Sucupira <>
Sun Nov 22 08:17:57 CET 2009


Hi, Jarrod.

I can't understand exactly what you want, so I'll give you an example.

Suppose DomainsSet is a sets of domains and DnsRec is a dns_rec. This
would be a list of the domains that are present in some resource
record and in DomainsSet:
[Domain || #dns_rr{domain = Domain} <- DnsRec#dns_rec.anlist,
sets:is_element(Domain, DomainsSet)]

Is that helpful?

Igor.

On Sun, Nov 22, 2009 at 3:52 AM, Jarrod Roberson <> wrote:
> 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,
>                            "",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


-- 
"The secret of joy in work is contained in one word - excellence. To
know how to do something well is to enjoy it." - Pearl S. Buck.


More information about the erlang-questions mailing list