in reply to How to I check if a value is present in an array?
grep doesn't do what you think. It returns a list of all elements where the search expression is true. The search expression in your case is $genes[$index], so if that's a true value, grep returns all the elements of @gl.
What you probably want to write instead is something like
for my $current (@genes) { if (grep { $_ eq $current } @gl) { print $current; } }
Though of course if either (or both) of these arrays is large, that is rather inefficient, and you might consider storing stuff in a hash in the first place.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to I check if a value is present in an array?
by Tux (Canon) on Aug 03, 2013 at 12:17 UTC |