in reply to Checking a string's presence within an array.
I am just curious which methods people use for this very common problem and which is the most popularGenerally I'll just use a grep and double negation e.g
Nice and efficient in newer versions of perl (5.6.1+ ?) as it won't build a list IRC. Even quicker would be a simple regexmy @array = qw/ a list of words /; print "yep, it's there" if !!grep { $_ eq "of" } @array; __output__ yep, it's there
It's not quicker on it's own (list size etc will effect performance) but if you prebuild the word list it should be quicker than grepping every time.my @array = qw/ a list of words /; print "yep, it's there" if "of" =~ /\b (?: ${\join('|', @array) }) \b/x; __output__ yep, it's there
_________
broquaint
|
---|