in reply to Extracting domain names from FQDNs
I understand processing speed is a factor, but with a little optimization... =)
Good luck.'kaboo
Update:
Here's a start. (I was bored.)
sub parse_fqdn { my $fqdn = shift; my @tlds = ( [qw(com net org)], # common [qw(gov edu co\.uk)], # not-so-common [qw(la li it po)] # downright odd (long list) ); foreach my $level (@tlds) { #warn "pass ". ++$pass; for(@{$level}) { return $1 if $fqdn =~ /\.(\w+?\.$_)$/; } } warn "unable to find domain from $fqdn\n"; return $fqdn; } my $domain = parse_fqdn('www.cs.niu.edu'); print "www.cs.niu.edu => $domain\n"; # niu.edu
|
|---|