A
abraxas
Hello,
i'm just a beginner using Perl and i have a little problem.
I have an html page with several links and a function that search the first
of those links. The function is the following:
search_first_link {
$cadena = $_[0];
$p = index ($cadena, '<a');
return -1 if ($p < 0);
$p1 = index ($cadena, 'href', $p);
return -1 if ($p1 < 0);
$p2 = index ($cadena, '>', $p1);
return -1 if ($p2 < 0);
$subcadena = substr ($cadena, $p1, $p2-$p1);
$reg_exp = "href=\"([^\"]+)\"";
return ($1) if ($subcadena =~ /$reg_exp/s);
return (-1);
}
It takes the html code as a parameter and returns the url of the first link
that it finds. For example, if the first link that the function find is the
following:
<a href="http://www.page.com">
My Page
</a>
it returns "http://www.page.com".
My problem is that also i want the function to return the text of the link,
"My Page".
How can I modify the function to get it?
Thanks and sorry for my awfull english!!!
i'm just a beginner using Perl and i have a little problem.
I have an html page with several links and a function that search the first
of those links. The function is the following:
search_first_link {
$cadena = $_[0];
$p = index ($cadena, '<a');
return -1 if ($p < 0);
$p1 = index ($cadena, 'href', $p);
return -1 if ($p1 < 0);
$p2 = index ($cadena, '>', $p1);
return -1 if ($p2 < 0);
$subcadena = substr ($cadena, $p1, $p2-$p1);
$reg_exp = "href=\"([^\"]+)\"";
return ($1) if ($subcadena =~ /$reg_exp/s);
return (-1);
}
It takes the html code as a parameter and returns the url of the first link
that it finds. For example, if the first link that the function find is the
following:
<a href="http://www.page.com">
My Page
</a>
it returns "http://www.page.com".
My problem is that also i want the function to return the text of the link,
"My Page".
How can I modify the function to get it?
Thanks and sorry for my awfull english!!!