You're right, I've not been very specific here. In my defense, that was a bit on purpose, because I think we miss some opportunities when we rush to a solution that just works instead of paying attention to why some approach is not good enough.

But again, I recognize that giving less details than necessary created some doubts. So let me explain what I need here. I'm managing a hosts file that must be periodically updated to filter many domain/hostnames known to be used on ads, trackers, annoyances and malware (by associating them with 0.0.0.0, which somewhat protects the configured machine from accidentally requesting anything from them).

As you might guess, this file gets very big and I'd like to filter out any record that's invalid anyway, so that it's pointless to add it to the hosts file. Sure, keeping only the legal addresses is not good enough for this purpose, but I intended to add warnings on output for those that are not legal.

Your suggestion to leverage libc to resolve it is nice, because then I know if it'll be resolved or not, which for this purpose is very important. On the other hand, considering these are hosts known to serve bad things, I'd rather avoid the queries, even if I'm not reaching these machines themselves.

return on_success() or die;


In reply to Re^2: Regex for hostname validation by hrcerq
in thread Regex for hostname validation by hrcerq

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.