First, you are not comparing strings, you are comparing arrays.
As this is not C, you don't need a for loop to get the length of an array: just say:
Assigning an array to a scalar assigns the length of the array to the scalar (OK, we're talking about context here, but I'm not going into a detailed discussion)$counter=@dna;$counter2=@comp;
And your cycles are a bit out of whack... you are saying:
I'll not write here a "correct" solution, since many other people already have. I'll just write a (commented) snippet for the case of strings:
my $dna; # the sequence, as a string my $comp; # the complement, as a string my $c2; ($c2=$comp)=~tr[ATGC][TACG]; # copy $comp into $c2, then exchange each + base in $c2 with its complement (using the tr-ansliteration operator +) print "Match!\n" if $dna eq $c2; # since $c2 is $comp's complement, it + should be equal to $dna
--
dakkar - Mobilis in mobile
In reply to Re: need help comparing DNA compliments
by dakkar
in thread need help comparing DNA compliments
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |