http://qs1969.pair.com?node_id=6637


in reply to How to find out if X is an element in an array?

You could do it like this:
my $element = "catchme"; my @array = ( "catchme", "if", "you", "can" ); if ( @found = grep { $_ eq $element } @array ) { my $found = join ",", @found; print "Here's what we found: $found\n"; } else { print "Sorry, \"$element\" not found in \@array\n"; }
I know that's a little longer than other answers but, I think this gives a little more detail and is easier to see how it works.

Replies are listed 'Best First'.
Re: Answer: How to find out if X is an element in an array?
by IlyaM (Parson) on Dec 08, 2001 at 02:56 UTC
    In most cases my should be used for declaration of variables instead of local. In most cases lexically scoped variables are more appropriative. See perlsub for details.

    --
    Ilya Martynov (http://martynov.org/)