in reply to Heuristic for parsing Host name and domain
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Heuristic for parsing Host name and domain
by Corion (Patriarch) on Aug 29, 2011 at 15:43 UTC | |
by flexvault (Monsignor) on Aug 29, 2011 at 18:16 UTC |