Holy Monks,

I have a piece of code that's driving me crazy. In short, I am trying to extract the link from <a href links through out my HTML page. I have the extract_tagged code working in other parts of my program, and from what I can tell it is exactly the same as this chunk that is mis-behaving.

Bad boy:

if (/<a href\=\"/) { my @link = extract_tagged($_, '<a href="', '">', undef, undef); print " @link[4]\n"; }

This code works:

else { my @text = extract_tagged($_, '<li>', '</li>', undef, undef); print " *@text[4]*\n"; }

Here is some text that the code is parsing:
<li><a href="menuheader.html">menuheader.cfm</a></li>

I know that the condition for the if statement is firing, because I can print out some debugging text inside. If I return a count of @link, its 3, but it should at least be 5, if I understand things right. I've tried returning @link positions 0-5, and all return null. I've tried escaping the quotes and/or equal signs as well.

FYI, I am fairly new to Perl, so go easy on me. ;)


In reply to extract_tagged by yacoubean

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.