http://qs321.pair.com?node_id=260407

Mr. Muskrat has asked for the wisdom of the Perl Monks concerning the following question: (cgi programming)

If I have a URL (http://www.perlmonks.org/index.pl for example),
how do I extract just the server information (www.perlmonks.org)?

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How do you extract the server from a URL?
by Mr. Muskrat (Canon) on May 23, 2003 at 17:30 UTC

    Use the URI module.

    use URI; my $url = 'http://www.perlmonks.org/index.pl'; my $uri = URI->new($url); my $server = $uri->host; print "URL: $url\n"; print "Server: $server\n";

Re: How do you extract the server from a URL?
by Abigail-II (Bishop) on May 23, 2003 at 18:37 UTC
    use Regexp::Common; my $url = 'http://www.perlmonks.org/index.pl'; print $3 if $url =~ /$RE{URI}{HTTP}{-keep}/;

    Abigail

Re: How do you extract the server from a URL?
by mendeepak (Scribe) on Mar 08, 2012 at 11:42 UTC

    use the URI Module

    my $url = URI->new( "http://www.perlmonks.org/index.pl" ); my $domain = $url->host; print $domain;

    Originally posted as a Categorized Answer.