more useful options | |
PerlMonks |
Re: How to I check if a value is present in an array?by rjt (Curate) |
on Aug 03, 2013 at 11:19 UTC ( [id://1047697]=note: print w/replies, xml ) | Need Help?? |
This seems rather similar to how to refer the index of an array to another array of the same length you asked a little over an hour ago, which already has several replies. This one is a bit different, though, so here's what I would suggest. Since you will be looping over @gl for every item in @genes, put @gl in a hash (only the keys matter). You can use a hash slice: my %gl; @gl{@gl} = undef;Then, the lookup is both simple and efficient: say for grep { exists $gl{$_} } @genes;Complete example:
Output:
In Section
Seekers of Perl Wisdom
|
|