array search in perl using grep

by rajesh 2008-11-19 21:10:34

We can use grep in a if condition to check whether a string is in a array

Example:
@arrayy = ('search 1', 'search 2', 'search 3', 'search 4');
$test="search 2"
if (grep {$_ =~ $test} @arrayy) {
print "found";
}


Tagged in:

3414
like
0
dislike
0
mail
flag

You must LOGIN to add comments