Tuesday, 6 August 2013

Perl extract domain name from email address inc tld but excluding subdomains

Perl extract domain name from email address inc tld but excluding subdomains

I'm trying to do what the title says and I've got this:
sub getDomain {
my $scalarRef = shift;
my @from_domain = split(/\@/,$$scalarRef);
if($from_domain[1] =~ m/^.*?(\w+\.\w+)$/){
print "$from_domain[1] $1" if($username eq 'xxx');
return $1;
}
}
Works fine for user@domain.com returning domain.com, but of course
domain.co.uk will return .co.uk and I need domain.co.uk. Any suggestions
on how to proceed with this one, I'm guessing a module and some suggest
some kind of tld lookup table.

No comments:

Post a Comment