Extracting host from a subdomain link

Discussion in 'Scripts' started by rvaibhav, Apr 19, 2011.

  1. #1
    Hi All,

    I am developing a perl script to extract all the internal links of a website.

    I want to check for the baseurl.

    Suppose I have a link
    $link = http://www.domain.com/url/par1=value1

    $url = URI->new($link)
    $hostname = $url->host();

    now I have www.domain.com in the variable $hostname

    Suppose I come across a link http://subdomain.domain.com/
    I need to be able to verify this link as an internal site link bcoz this is in the subdomain.

    But if I do $url->host() for the link http://subdomain.domain.com/,

    I will get the host as subdomain.domain.com, and when i compare this with the variable $hostname, it will return false.

    Is there any method by which I can extract out the base domain from subdomain hosts.

    I would appreciate any help!

    Thanks
    Vaibhav
     
    rvaibhav, Apr 19, 2011 IP