So, 5 years ago I was trying to solve (efficiently) 80 regexs run over a 10K document. That quest ended in success. Now I am wrestling with filtering out lines of an array that match any entry of an array of regexs I am giving 'grep' a shot but am having a problem generalizing a single test into multiple tests.
--Thanks---
Thanks for the quick response. Another nifty tool!!
Perldoc shows:
@foo = grep {!/^#/} @bar; # weed out comments
I want to replace that single regex with a loop over an array of 'qr's.
my @regs =(
qr/split/ ,
qr/se.d/ ,
qr/open/,
qr/print/,
# might be another 100 in here #
);
my @bar;
my @foo; push @foo, "still empty";
open INP , "<../IPutils.pm"; #random code
while (<INP>){ push @bar, $_; }
print @bar, "\n--EOD-----------\n";
@foo = grep{
# !/^\s*#/ #sample from Perldocs
#{ #causes compile error
#( #causes compile error
my $final =1; #default true
foreach my $r (@regs){
$final = 0 if ( $r ); #match means drop this line
}
$final; #last value of the block hmmmmm
#)
#}
}@bar;
print @foo;
'return' shouldn't be the correct mechanism to tell grep true/false. But when I run this, the second print (@foo) produces nothing.
It is always better to have seen your target for yourself, rather than depend upon someone else's description.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link or
or How to display code and escape characters
are good places to start.