Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

How do you extract the server from a URL?

by Mr. Muskrat (Canon)
on May 23, 2003 at 17:29 UTC ( [id://260407]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://260407]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-25 11:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found