Perl in_array()

Perl can use the grep function as the equivalent of PHP’s in_array() function.  Essentially

$found = grep $_ eq $my_value, @my_array

Note, the grep() function is world unto its own, it can do quite a bit more than just this.  $found is actually $my_value if it finds it, which tends to evaluate to ‘True’ in Perl.

2 thoughts on “Perl in_array()

Leave a Reply