Quote:
> Hello,
> Given the following regex:
> $file2 =~ /TABLE\s+70.*?TELEVISION.*?(\d{1,3}\.\d)\D+/s;$P33A23 = $1
> I want a way to have the search fail or to stop the search if it
> finds "TABLE 71".
> Any ideas how I might accomplish this?
> Lance
Hello Lance:
I'm not sure I understand your entire objective here, but I presume
this line is inside a block such as
open F, $someFile;
while <F>
{last if /TABLE\s+71/; # add this line to short-circuit the search?
$file2 =~ /TABLE\s+70.*?TELEVISION.*?(\d{1,3}\.\d)\D+/s;
$P33A23 = $1;
}
It seems odd to loop though a whole file to store one value. So lets
look at another tact (I havent tested this code, beware it's FRIDAY
and almost beer-thirty)..
open F, $someFile;
# snag the file file cram it into a scalar, close it to be tidy
close F;
# now truncate the inputfile at /TABLE\s+71/
$f =~ s/TABLE\s+71.+$//sm;
$f =~ s/^.*TABLE\s+70.*?TELEVISION.*?(\d{1,3}\.\d).+$/$1/;
# at this point $f either contains $1, if it matched, or the truncated
file if
# it didn't. There are a few ways to test that, perhaps another regex?
$f = '' unless $f =~ /^\d{1,3}\.\d$/;
Again I'm not certain this is what you were after, if not please
disregard. However, note that this approach is loop-less, which can be
desirable. Dont forget your old friends Mr "Strict" and Mr warnings
either!
Finally- that variable $P33A23 looks very odd, as if perhaps its
related to some coordinate like (33,23) or something like that? If so,
and you have others with similar names, I recommend a hash for them
like
my $p = {};
.
.
$p->{23}={};
$p->{23}{33} = blah blah...
But again, I may be misinterpreting between the lines of your post.
Have a great Perl weekend! Oh wait I forgot the obligatory flame that
the other poster said all contributors give here. Let's see.. *think*
*think*
Ahhh forget it I need a beer!
-Gx