Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: grep with multiple choice

by ferreira (Chaplain)
on Jun 11, 2007 at 11:55 UTC ( #620473=note: print w/replies, xml ) Need Help??


in reply to grep with multiple choice

grep { /^Julia_Roberts/ } @arr
should be enough. There's nothing particularly different with this "grep with multiple choice". The only thing it seems you are missing is that the grep block can match different values provided you code a suitable matching sub, like I did with a regex. If your problem is really to find out the array elements starting with $s, this will work:
grep { /^\Q$s\E/ } @arr; # regex with quoted interpolation # or grep { index $_, $s == 0 } @arr; # more efficient

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2020-10-21 14:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (217 votes). Check out past polls.

    Notices?