[erlang-questions] How to match on a nested record against a dict
Jarrod Roberson
jarrod@REDACTED
Mon Nov 23 06:25:56 CET 2009
On Sun, Nov 22, 2009 at 2:17 AM, Igor Ribeiro Sucupira <igorrs@REDACTED>wrote:
> 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.
>
> Ok have tried and tried, and your snippet won't compile.
I have both Erlang books and can't figure out how to do this logic.
here is how I would do it in pseudo-code in languages that I am familar
with.
for (dns_rr in dns_rec.getAnList())
{
if (dns_rr.domain == "_test._tcp.local")
{
// do some logic here
}
}
receiver(Subs) ->
receive
{udp, _Socket, IP, InPortNo, Packet} ->
{ok,DnsRec} = inet_dns:decode(Packet),
% this is where I want the "domain" detecting logic from the
dns_rr records
io:format("~n~nFrom: ~p~nPort: ~p~nData:
~p~n",[IP,InPortNo,DnsRec]),
receiver(Subs);
stop ->
true;
AnythingElse ->
%io:format("RECEIVED: ~p~n",[AnythingElse]),
receiver(Subs)
end.
More information about the erlang-questions
mailing list