ast has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm trying to get the FQDN from a Url. I tried this:
$s = "http://www.blablubber.net/bla/index.html"; ($url,undef) = split(/\//,$s); @domain = split(/\./,$url); $tld = pop(@domain); $domainname = pop(@domain); $fqdn = "$domainname.$tdl";
This code is not really useful when a Url is for example http://www.bla.co.uk/blubber/index.html ;-) Can anyone please give me a hint?

Thx,
Axel

Replies are listed 'Best First'.
Re: Get FQDN from Url
by jamesduncan (Novice) on Jul 23, 2003 at 15:06 UTC
    use the URI module!
    use URI; my $uri = URI->new( "http://www.blablubber.net/bla/index.html" ); my $domain = $uri->host();
    Regards, James.
Re: Get FQDN from Url
by Abigail-II (Bishop) on Jul 23, 2003 at 15:13 UTC
    use Regexp::Common; $host = $3 if $url =~ /$RE{URI}{HTTP}{-keep}/;

    Abigail

Re: Get FQDN from Url
by roju (Friar) on Jul 23, 2003 at 15:04 UTC
    Although you could try to extract the FQDN yourself, there's a good chance you could miss some special case or other. Luckily CPAN has Regexp::Common::URI.
Re: Get FQDN from Url
by sauoq (Abbot) on Jul 24, 2003 at 00:05 UTC

    Just to get the terminology straight, an absolute URL is not required to contain a fully qualified domain name (FQDN). It could contain a hostname or an IP address, for example.

    -sauoq
    "My two cents aren't worth a dime.";