Reputation:
I have written a perl program to find the percentage GC content in the given DNA string.But the program is executing the error situation(else part of conditional statement)
$dna = "AGTC";
$a = 0;
$g = 0;
$t = 0;
$c = 0;
for ($p = 0; p < length $dna; ++$p) {
$ch = substr($dna,$p,1);
if($ch eq 'A') {
++$a;
} elsif($ch eq 'G') {
++$g;
} elsif($ch eq 'T') {
++$t;
} elsif($ch eq 'C') {
++$c;
} else {
print "error";
}
}
$total = $a + $g + $t + $c;
$gc = $g + $c;
$percentagegc = ($gc/$total) * 100;
print "percentage gc content is = $percentagegc";
Please help.
Upvotes: 0
Views: 93
Reputation: 663
You're missing a $
in one of your usages of $p
in this line:
for($p = 0;p < length $dna;++$p)
^ -- here
Fixing that and running your script I correctly get:
percentage gc content is = 50
Upvotes: 4