"why does my regex simply not match, return false, the if not execute, and the loop continue?"--

First of all, the code is working like that, because that is what you have it programmed to do. Your regular expression is failing. When a regex fails it return a false value which you if is evaluating, seeing is obviously not true, and not executing its conditional block.

So, the tricky part is, why does your regex not match? Well, there are a couple of things. For one, you are using the '.*?' construct quite a bit. You mentioned the Death to Dot Star! node, but the construct you are using is different than .* is a very imortant way. The question mark makes the .*, non--greedy...matching as little as it can. It looks like you wanted to use the greedy nature of .* to your advantage, but you added the question mark, changing its nature.

Watch what happens with these two examples:

$str = "<tr><td width="0" align="center"><font face="Arial" size="2">5 + Digits </font></td>"; if ($str =~ m/(<[Tt][Rr].*>)/ ) { # using .* print $1, "\n"; } # or $str = "<tr><td width="0" align="center"><font face="Arial" size="2">5 + Digits </font></td>"; if ($str =~ m/(<[Tt][Rr].*?>)/ ) { # using .*? print $1, "\n"; }
The regexes in both example will succeed, but the output will be very different.

One more thing: You are saying while (<FH>), which is all well and good, but your regex is testing the entire contents of the table. Unless that table is all on one line of the file your regex has way too much in it.

Now, knowing what you now know about greediness and non-greediness, go back and tweak your regex.

Amel - f.k.a. - kel


In reply to Re: Problem with CGI script not working (regex at fault) by dsb
in thread Problem with CGI script not working (regex at fault) by deryni

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.