in reply to Using regular expressions with arrays

Youre getting these errors because your while loop loops 468 times. Each time it iterates it increases both $X and $Y, which in turn will cause the loop to search for an array value that indeed is not initialized. Either add 466 more items to each array, or decrease the amount of loops.

I would use a different approach myself. Soemthing like:
use strict; use warnings; my @GI = ( "gi|Q384722390|emb|WP_938420210.1|Gene name", "gi|342546780|emb|WP_934203412.1|Gene name" ); my @Accession = qw( WP_938420210.1 WP_934203412.1 ); my $i = 0; for my $A(@Accession) { for my $G(@GI) { if ( $A =~ $G ) { print "$G\n"; } } }

Replies are listed 'Best First'.
Re^2: Using regular expressions with arrays
by AnomalousMonk (Archbishop) on Apr 13, 2015 at 18:32 UTC

    This approach depends on the fact that the CSV separator character in  "gi|Q384722390|emb|WP_938420210.1|Gene name" ( |(pipe)) is also the regex ordered alternation operator, but ignores the fact that  . (dot) in  |WP_938420210.1| is also a regex metacharacter that matches (almost) anything. Is this a good idea?


    Give a man a fish:  <%-(-(-(-<