function modification

From: abraxas (adj_at_demadrid.com)
Date: 10/31/03


Date: Fri, 31 Oct 2003 14:05:18 +0100

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!!! :-)



Relevant Pages

  • Re: Walking a tree and extracting info... Problems
    ... Learn to use the Perl debugger and to use the ... foreach $file (@thefiles) { ... push @lines, $_; # push the data line onto the array ... Perl has allocated "@lines" once for the whole program; when you process the next file in the directory you push the lines on the bottom; the match for the HTML title then fires every time. ...
    (comp.lang.perl.misc)
  • Re: HTTP Filtering and Threads...
    ... You are trying to parse HTML with regular expressions. ... This is not Perl. ... # Some irrelevant code stuff... ... foreach $userID { ...
    (comp.lang.perl.misc)
  • RE: question
    ... well it's really HTML that's the problem. ... > was whether perl was appropriate, not how to do it in perl. ... > this e-mail message or disclose its contents to anybody else. ... > should check this e-mail and any attachments for viruses. ...
    (perl.beginners)
  • Re: Two Perl programming questions
    ... directory names using Perl. ... I can debug through my Perl script and ... How would Perl create the dynamic HTML that I ... Perl is general purpose programming language. ...
    (comp.lang.perl.misc)
  • Re: How to write to drive A: from CGI Perl
    ... >> If that does not look weird to you, then please go back to basics. ... Please (assuming that the quoted text is an actual excerpt from the HTML ... You will have a better version of Perl? ... for HTML or Perl or CGI or anything. ...
    (comp.lang.perl.misc)