Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: boolean IN(); function in perl like

by xdg (Monsignor)
on Jan 14, 2005 at 21:40 UTC ( [id://422398]=note: print w/replies, xml ) Need Help??


in reply to Re: boolean IN(); function in perl like
in thread boolean IN(); function in perl like

I'm surprised to see only grep examples with "eq". You can also do this with regex interpolation (being careful to match the whole thing, of course):

print "found!" if grep(/^$e$/, @a);

This might be useful if, for example, you didn't care about matching case:

print "found!" if grep(/^$e$/i, @a);

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^3: boolean IN(); function in perl like
by gaal (Parson) on Jan 14, 2005 at 22:02 UTC
    You'd better run $e through quotemeta if you do this, or use the equivalent \Q .. \E re syntax.

    (If case does matter, an eq check is definitely going to be faster. If it doesn't, precomputing lc $e and comparing that to lc $_ is still liable to be faster, though it's worth a benchmark. Of course, very often this is not a concern.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-19 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found