in reply to comparing strings
Also, there are quite a few problems in your original code. First, the value that you want to loop/iterate over is the number N when you are looking at the Nth character. But the foreach loop will set $base to each of the values in @lines1 and then to all the values in @lines2. You cannot get a pair of elements from two different arrays using a foreach loop. Also note that inside the loop, you are comparing the first elements of the array each time. You want to compare a different pair of elements each time through the loop. Lastly, @lines1[0] is invalid (at least until Perl6), and what you need to say instead is $lines1[0].my $dna1 = 'CACTATGAGTGATCGC'; my $dna2 = 'ACTGACTAATGCGTTG'; print "$dna1\n$dna2\n"; for (0 .. length($dna1)-1) { if (substr($dna1,$_,1) eq substr($dna2,$_,1)) { print ' '; } else { print '*'; } } print "\n"; __END__ # prints this: CACTATGAGTGATCGC ACTGACTAATGCGTTG **** ** * *****
HTH and keep trying!
blokhead
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: comparing strings
by Anonymous Monk on Oct 30, 2002 at 16:26 UTC | |
by petral (Curate) on Oct 30, 2002 at 17:52 UTC | |
by graff (Chancellor) on Oct 31, 2002 at 04:47 UTC |