Based upon your requirements I would do something like this. You might also add a hash of all valid TLD combinations, but that might be what you want to get.
#!/usr/bin/perl -w use strict; while( my $url = <DATA> ) { chomp($url); my @Url = split(/\./,$url); if ( length($Url[$#Url]) == 3 ) { print "$url:\t\tTLD is '".$Url[$#Url]."'\n"; } else { print "$url:\t\tTLD is '".$Url[$#Url-1].".".$Url[$#Url]. +"'\n"; } } 1; __DATA__ www.drane.fresel.co.uk www.drane2.ws.uk www.drane3.Intern.com
result:
www.drane.fresel.co.uk: TLD is 'co.uk' www.drane2.ws.uk: TLD is 'ws.uk' www.drane3.Intern.com: TLD is 'com'
I use this in a Spam detection program. It gets allot more complicated than this!
Good Luck.
"Well done is better than well said." - Benjamin Franklin
In reply to Re: Heuristic for parsing Host name and domain
by flexvault
in thread Heuristic for parsing Host name and domain
by persistence911
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |