Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: grep trouble

by LanX (Bishop)
on Apr 17, 2011 at 15:45 UTC ( #899820=note: print w/replies, xml ) Need Help??


in reply to Re^2: grep trouble
in thread grep trouble

I'm still not sure what you're trying to achieve here, cause your grep returns the PATTERNs which matched.

Are those patterns simple words? If yes you could consider constructing an or-regex:

DB<100> @patterns=qw#one two three# DB<101> $str="one two" DB<102> $re=join "|",@patterns DB<103> print $str =~ m/($re)/g onetwo

UPDATE:

just noticed there are still subtle differences:

DB<106> $str="two one two" DB<107> print $str =~ m/($re)/g twoonetwo DB<108> print grep {$str=~/$_/} @patterns onetwo

Cheers Rolf

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://899820]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2018-07-18 12:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (392 votes). Check out past polls.

    Notices?