How do I extract the domain out of an URL? Is there a Perl Module? I could not find any.
A:
I would just use a Regular Expression, although you could also do it with a series of substring operations..
Miky Dinescu
2009-05-05 21:44:52
No point re-inventing the wheel.
David Precious
2009-05-06 12:18:04
@David, you're right..
Miky Dinescu
2009-05-06 15:57:08
+1
A:
Perhaps Regexp::Common:URI?
Update: URI as suggested by friedo sounds better?
toolkit
2009-05-05 21:46:11
+14
A:
The URI module can parse URIs for you in a nice OO-ish way. To get the domain part:
my $url = URI->new( "http://www.stackoverflow.com/" );
my $domain = $url->host;
print $domain;
friedo
2009-05-05 21:46:36
The link in the answer points to this very question. I think you mean it to be: http://search.cpan.org/~gaas/URI-1.53/URI.pm
Dennis Williamson
2010-03-23 06:51:32
A:
Using the regex method does have some pitfalls, for one he can test the url with the other methods, like the type (http, ftp, https, gopher, xmmp) and it will handle a wide variety of hosts (name, ipv4, ipv6), and handle the file: and unc ape-crazy stuff.
hpavc
2009-05-05 22:31:39