Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

How do you extract the server from a URL?

by Mr. Muskrat (Canon)
on May 23, 2003 at 17:29 UTC ( #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

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? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2021-09-28 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?