andybshaker has asked for the wisdom of the Perl Monks concerning the following question:
Hi, please bear with me as I'm new to Perl. I have two arrays: one is a list of full gene names (GI), and one is a list of just their accession numbers (Accession). It looks like:
my @GI = ("\Qgi|Q384722390|emb|WP_938420210.1|Gene name\E","\Qgi|34254 +6780|emb|WP_934203412.1|Gene name\E"); my @Accession = ("WP_938420210.1","WP_934203412.1");
That is only an abbreviated example. In the real program, the GI list is much longer because it contains all the genes, and the Accession array only contains the Accession numbers of the ones I'm interested in. The Accession numbers are part of the GI full name, so I thought I could use a regular expression to go through each element of the arrays and find matches for the 469 accession numbers, like this:
my $X = 0; my $Y = 0; while($X <= 468){ if(/$Accession[$X]/ =~ $GI[$Y]){ print $GI[$Y]; $X = $X + 1; $Y = 0; } else{$Y++}; }
However, when I do this, I get the error "Use of uninitialized value in pattern match (m//) and also use of uninitialized value within @GI in regexp compilation. Does anyone know what I am doing wrong? Thank you!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using regular expressions with arrays
by AnomalousMonk (Archbishop) on Apr 13, 2015 at 16:37 UTC | |
|
Re: Using regular expressions with arrays
by hippo (Archbishop) on Apr 13, 2015 at 16:50 UTC | |
|
Re: Using regular expressions with arrays
by jeffa (Bishop) on Apr 13, 2015 at 16:51 UTC | |
|
Re: Using regular expressions with arrays
by kennethk (Abbot) on Apr 13, 2015 at 16:53 UTC | |
by AnomalousMonk (Archbishop) on Apr 13, 2015 at 18:47 UTC | |
|
Re: Using regular expressions with arrays
by james28909 (Deacon) on Apr 13, 2015 at 17:00 UTC | |
by AnomalousMonk (Archbishop) on Apr 13, 2015 at 18:32 UTC |