http://qs1969.pair.com?node_id=1089040

Wiggins has asked for the wisdom of the Perl Monks concerning the following question:

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.