Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Perl
Perl Misc
function modification
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="abraxas, post: 4746676"] 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="[URL]http://www.page.com[/URL]"> My Page </a> it returns "[URL]http://www.page.com[/URL]". 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!!! :-) [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Perl
Perl Misc
function modification
Top