in reply to Heuristic for parsing Host name and domain
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.
|
|---|