vit has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
I do not want to reinvent the wheel. So what would be the best way to compare the "root part" of two urls.
For example
http://xyz.com and www.xyz.com and ...xyz.com/something......
should be the same. I need to make sure that xyz is the same.
I am ready to sacrifice difference between xyz.com, xyz.net, etc.

Replies are listed 'Best First'.
Re: compare two urls
by Anonymous Monk on Jul 15, 2009 at 15:27 UTC
Re: compare two urls
by ikegami (Patriarch) on Jul 15, 2009 at 15:44 UTC
    As far as we can tell, "www.xyz.com" doesn't share the same "root part" as "http://xyz.com". "www.xyz.com" means ".../www.xyz.com" if it's a URI as you claim.
Re: compare two urls
by mzedeler (Pilgrim) on Jul 15, 2009 at 18:14 UTC

    As suggested by others, the URI module is a good place to start, but you are not being sufficiently explicit wrt the requirements. If you want an algorithm that claims that the following two URIs are identical:

    http://www.xyz.com/

    and

    http://xyz.com/

    Then please note that they are not guaranteed to point to the same web pages.