in reply to Problem with CGI script not working (regex at fault)
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:
The regexes in both example will succeed, but the output will be very different.$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"; }
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Problem with CGI script not working (regex at fault)
by deryni (Beadle) on Jul 30, 2001 at 01:58 UTC |