I am using gethostbyname() to check if the domain part of an email address has a valid DNS. Why is it that for some addresses like say <foo@bar.com> 'bar.com' has a DNS entry but for other addresses such as <foo@baz.com> 'baz.com' does not have a DNS entry but 'www.baz.com' does. In real life both these email addresses are valid and deliverable, its just that when you check the domain part with gethostbyname() you need to append the 'www.' prefix. I have settled on this:

for (keys %emails) { my ($domain) = $_ =~ m/<[^@]+@([^>]+)>/; my $dns = gethostbyname($domain) || gethostbyname("www.$domain"); $dns = $dns ? "OK DNS" : "No DNS"; print "$dns email: $_ page(s): $emails{$_}\n"; }

Can someone please explain this seemingly random requirement for 'www.' to me?

Thanks


In reply to gethostbyname() and www prefix by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.