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

Re: using grep to match more than two words

by Samy_rio (Vicar)
on Jun 12, 2007 at 06:25 UTC ( #620638=note: print w/ replies, xml ) Need Help??


in reply to using grep to match more than two words

Hi sroy5, try this,

use strict; use warnings; my @arr1 = ("Sun", "Moon", "Venus", "Pluto", "Neptune"); ((grep/^(Sun|Moon)$/, @arr1) == 2) ? (print "True") : (print "False");

Anyway first look into these links How do I post a question effectively? & How (Not) To Ask A Question

Regards,
Velusamy R.


eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';


Comment on Re: using grep to match more than two words
Select or Download Code
Re^2: using grep to match more than two words
by blazar (Canon) on Jun 12, 2007 at 08:29 UTC
    ((grep/^(Sun|Moon)$/, @arr1) == 2) ? (print "True") : (print "False");

    This is not reliable if @arr1 is allowed to contain duplicates, it is deemed to give false positives and false negatives, and the OP wrote nothing about that possibility.

      Oh Dang! I was going to post which would had counted the number of matches (did not post as similar method had already been shown) but I completely missed the possibility of duplicates. Thanks much.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-09-20 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (152 votes), past polls