downer has asked for the wisdom of the Perl Monks concerning the following question:
Can any monks think of how to improve this? Is there any module for doing the following which i didnt find?my $tld; my $url = 'http://www.someurl.com/index.html'; if($url =~ /(http:\/\/)?(.+?)\//) { my $host = $2; my @host_parts = split(/\./, $host); my $len = @host_parts; if(length($host_parts[-1]) <= 2 && $len > 2) { $tld = join('.',@host_parts[-2..-1]); } else { $tld = $host_parts[-1]; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding the Top Level Domain from a URL
by ikegami (Patriarch) on Jun 17, 2009 at 22:10 UTC | |
|
Re: Finding the Top Level Domain from a URL
by Anonymous Monk on Jun 18, 2009 at 02:49 UTC |