⭐ in reply to How to find out if X is an element in an array?
You could do it like this:
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.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"; }
|
---|
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 Section
Seekers of Perl Wisdom