in reply to Re: check if an element exists in array
in thread check if an element exists in array

sub isInList { my( $d, $it ) = ( "\0", @_ ); join( $d, '', @_, '' ) =~ /$d\Q$it\E$d/ }

Caveat: This treats all the values as strings. Input values which are not strings will get stringified! This may or may not yield the desired results.

Replies are listed 'Best First'.
Re^3: check if an element exists in array
by RecursionBane (Beadle) on Apr 13, 2011 at 18:13 UTC
    Elegant! Does Perl automagically return the last modified variable when returning from a subroutine?

      "Last modified variable"? No, it returns the value of the last evaluated expression.