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:
I want to replace that single regex with a loop over an array of 'qr's.@foo = grep {!/^#/} @bar; # weed out comments
'return' shouldn't be the correct mechanism to tell grep true/false. But when I run this, the second print (@foo) produces nothing.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;
It is always better to have seen your target for yourself, rather than depend upon someone else's description.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: grep with looped tests
by LanX (Saint) on Jun 06, 2014 at 15:31 UTC | |
by RichardK (Parson) on Jun 06, 2014 at 15:57 UTC | |
by LanX (Saint) on Jun 06, 2014 at 16:03 UTC | |
by Laurent_R (Canon) on Jun 06, 2014 at 20:55 UTC | |
by LanX (Saint) on Jun 07, 2014 at 15:45 UTC | |
by Laurent_R (Canon) on Jun 08, 2014 at 09:24 UTC | |
by LanX (Saint) on Jun 08, 2014 at 12:10 UTC | |
Re: grep with looped tests
by betterworld (Curate) on Jun 06, 2014 at 15:31 UTC | |
Re: grep with looped tests
by LanX (Saint) on Jun 06, 2014 at 15:46 UTC |
Back to
Seekers of Perl Wisdom