Perlfunc: in_array()

If you need to determine if an array contains a specific element you can use this function:

sub in_array {
        my $needle   = shift();
        my @haystack = @_;

        foreach my $l (@haystack) {
                if ($l eq $needle) { return 1; }
        }

        return 0;
}

Note: If you want to check integers just change the eq to ==

Leave A Reply
All content licensed under the Creative Commons License