Hello everyone,

Here's what I need to do: I need to take each of the words in one
List1, search for their presence (or not) in a second List2 and make a
new list with all the words in both. These are lists of gene names,
which can often include numbers and symbols in addition to letters.

The very newbie code that I wrote performs well, but it's missing the
words that have parentheses in them (for instance "Su(var)2-5").
Below are examples of the lists that I'm working with, the code that
I'm using, and the output.

I realize that there may be a number of ways to do what I need to do
(most of them better, I bet), and I'd love to learn about them. But
now I'm mostly curious about why grep// cannot "see" words with
parentheses in either (or both lists). I suspect the trick may be
somehow escaping the (), but I tried a number of ways of doing that to
no avail.

Any help will be greatly appreciated! And as usual, if you ever have
questions about molecular biology and genetics, fire away - I'd love
to pay the favor back.

Thanks in advance,
Mariano

Example of List 1

numb
Dl
cad99C
ham
esg
Stat92E
Hh
l(2)Lg
neur
CG32150
sox15N
Su(var)2-5
E(spl)-m4
ci
brd
vvl

Example of List 2

Src42A
cad99C
ham
Hh
l(2)Lg
neur
sox15N
numb
ubx
Su(var)2-5
esg
E(spl)-m4
ci
ttk
egfr
brd
ocho
vvl
CG32150

############## SCRIPT BEGINS
#!usr/bin/perl
use warnings;

print "\nEnter path to List 1\n\n";
$path1 = <STDIN>; chomp $path1;

print "\nEnter path to List 2\n\n";
$path2 = <STDIN>; chomp $path2;

open (INPUT1, "$path1"); open (INPUT2, "$path2"); open (INPUT3, "$path3");
@array1 = <INPUT1>;
@array2 = <INPUT2>;

my ($array1,$array2,$in1and2);

my $ctr1 = 0;
while ($ctr1 < @array1){
        if(grep(/^$array1[$ctr1]$/,@array2)){
                push (@in1and2,$array1[$ctr1]);
        }
        $ctr1 +=1;
}

print "in 1= ".@array1."\nin 2= ".@array2."in 1 and 2= ".@in1and2."\n\nDone!";

exit;

######

The output is...

in 1= 16
in 2= 19
in 1 and 2= 11

Done!

...when it should have been...

in 1= 16
in 2= 19
in 1 and 2= 14

but it's not "seeing" l(2)Lg, Su(var)2-5, E(spl)-m4 in both lists...
(I know this based on troubleshooting)

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to