Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^2: grep trouble

by LogMiner (Novice)
on Apr 17, 2011 at 14:04 UTC ( #899814=note: print w/replies, xml ) Need Help??

in reply to Re: grep trouble
in thread grep trouble

Thanks davido. I guess the grep-evaluated block should look like:

{$_ eq "" or "" =~ /$_/}

(of course the actual logic in my script is different, as there are easier ways to do the above)

Replies are listed 'Best First'.
Re^3: grep trouble
by LanX (Archbishop) on Apr 17, 2011 at 15:45 UTC
    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


    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

Re^3: grep trouble
by LanX (Archbishop) on Apr 18, 2011 at 10:37 UTC
    you also have to check for undef:

    DB<120> print scalar grep {"a"=~/$_/} ("a","",undef) 3

    Cheers Rolf

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://899814]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2018-12-12 00:17 GMT
Find Nodes?
    Voting Booth?
    How many stories does it take before you've heard them all?

    Results (57 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!