Hi guys,
First off, great job with libwww-perl. :)
I was wondering if there was a method to return the top-level domain name
for URIs? I couldn't find one, so here's my attempt at "hacking" one into
LWP:
I looked where the host() method was located, and found it in _server.pm;
thus I put in this one and it seems to work fine for my needs. It's
read-only though, it doesn't "set" the domain name (perhaps someone could
improve upon my code?)
sub domain
{
my $self = shift;
my $hostname = $self->host();
# first regex: make sure it's not an IP
# 2nd regex: capture actual domain name
if (($hostname !~ /^[0-9.]+$/) && ($hostname =~ m{([^.]+\.)*([^.]+)$})) {
return uri_unescape($1 . $2);
} else {
return uri_unescape($hostname);
}
}
Any tips/suggestions would be helpful... I'm not sure my code is the best
(TMTOWTDI), or whether my regexp meets the RFCs etc. Better yet, please
incorporate a TLD method into LWP! :)
---
John Lim Eng Hooi * [EMAIL PROTECTED] | [EMAIL PROTECTED]