How could I get some part of url?
For example:
http://www.facebook.com/xxxxxxxxxxx
http://www.stackoverflow.com/yyyyyyyyyyyyyyyy
I
use feature qw( say state );
use Domain::PublicSuffix qw( );
use URI qw( );
# Returns "domain.tld" for "subdomain.domain.tld".
# Handles multi-level TLDs such as ".co.uk".
sub root_domain {
my ($domain) = @_;
state $parser = Domain::PublicSuffix->new();
return $parser->get_root_domain($domain);
}
# Accepts urls as strings and as URI objects.
sub url_root_domain {
my ($abs_url) = @_;
my $domain = URI->new($abs_url)->host();
return root_domain($domain);
}
say url_root_domain('http://www.facebook.com/'); # facebook.com
say url_root_domain('https://www.facebook.com/'); # facebook.com
say url_root_domain('http://mobile.google.com/'); # google.com
say url_root_domain('http://www.theregister.co.uk/'); # theregister.co.uk
say url_root_domain('http://www.com/'); # www.com