in reply to Using URI::URL to determine resources within a site
It produces the follwing output...use URI; $u1 = URI->new('http://www.comp.leeds.ac.uk/Perl/'); $u2 = URI->new('http://www.comp.leeds.ac.uk/Perl/filehandling.html'); print "u1.host=",$u1->host(),"\n"; print "u2.host=",$u2->host(),"\n"; if ($u1->host() eq $u2->host()) { print "URL's host are the same\n"; } else { print "oops\n"; }
It doesn't use URI::URL, but I'm not sure that you need to.u1.host=www.comp.leeds.ac.uk u2.host=www.comp.leeds.ac.uk URL's host are the same
PARSING URIs WITH REGEXP As an alternative to this module, the following (official) regular exp +ression can be used to decode a URI: my($scheme, $authority, $path, $query, $fragment) = $uri =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:# +(.*))?|; The URI::Split module provide the function uri_split() as a readable a +lternative.
use URI; $u1 = URI->new('http://www.comp.Leeds.ac.uk/Perl/')->canonical(); $u2 = URI->new('http://www.comp.leeds.ac.uk/Perl/filehandling.html')-> +canonical(); print "u1.host=",$u1->host(),"\n"; print "u2.host=",$u2->host(),"\n"; if ($u1->host() eq $u2->host()) { print "URL's host are the same\n"; } else { print "oops\n"; }
|
|---|