Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: grepping arrays

by George_Sherston (Vicar)
on Jun 21, 2003 at 21:52 UTC ( #267875=note: print w/ replies, xml ) Need Help??


in reply to grepping arrays

I think the main thing going wrong is that your first argument needs to be a block of code rather than a scalar. grep works by running the block of code for each element in the array and returning the number of times it was true (or, if you did @output = grep... it gives you the list of elements from your input array for which it was true... but you don't care about that).

So this

if(grep($username =~ m/\b$_\b/, @ignore)) { print "That didn't quite work"; }
... may do what you want. (the \bs are so you only catch whole words).

George Sherston


Comment on Re: grepping arrays
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2015-07-02 22:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (46 votes), past polls