I'm no Perl monk, and I'm sure there may well be better ways of doing it, but the code below might help. I expect there is some module out there with valid TLDs, but, regardless, if you happen to know each of the TLDs you'll be dealing with then you could do something like the code below maybe:

push (my @domains,'www.drane.fresel.co.uk','www.drane2.ws.ru','www.dra +ne3.Intern.com'); for (@domains) { my $name=''; my $tld=''; if ($_=~/\.co\.uk$/) { $name=substr($_,0,rindex($_,'co.uk')-1); $tld='co.uk'; } elsif ($_=~/\.ws\.ru$/) { $name=substr($_,0,rindex($_,'ws.ru')-1); $tld='ws.ru'; } elsif ($_=~/\.com$/) { $name=substr($_,0,rindex($_,'com')-1); $tld='com'; } print "\$name:\t$name\n\$tld:\t$tld\n\n"; }

... where you just read all your domain names into a list array, and then simply process the list.


In reply to Re: Heuristic for parsing Host name and domain by DanielSpaniel
in thread Heuristic for parsing Host name and domain by persistence911

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.