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 Responses to “Perl in_array()”

  1. Bert says:

    g5sQq9 Thanks alot – your answer solved all my problems after several days struggnlig

  2. Roman says:

    Thanks – this works fine :-)

Leave a Reply

You must be logged in to post a comment.