hi Berislav,
i think, you have 2 problems on your code:
- for ($lb=0; $lb<length $dna; ++$lb), the lenght of the array must be length($dna) -1 (the last elemet cannot be compared with anything ... perl accepts this, though)
- the 'tr' only tries to convert between lowercase letters. The example you gave us have uppercase letters ... the result isn't the same ...
-
I've retouched your script, so the problem of the large string will not affect you
#!/usr/bin/perl -w
use strict;
system "clear";
print "Palindrome - gamma version\n";
print "--------------------------\n\n";
print "Please enter DNA filename: ";
my $filename=<STDIN>;
chomp $filename;
die "No such file...exiting\n\n" unless (-e $filename);
open(DNASEQ, $filename) or die "Cannot open file...exiting\n\n";
my $last_protein;
my $count_of_2=0;
while (<DNASEQ>) {
chomp;
my ($lba,$rba)= ($last_protein, undef);
for (my $lb = 0; $lb < (length) - 1; ++$lb) {
$lba = substr ($_, $lb, 1);
$rba = substr ($_, $lb+1, 1);
$rba =~ tr/atgcATGC/tacgTACG/;
++$count_of_2 if ($lba eq $rba);
}
$last_protein = $rba;
}
print "Number of 2bp palindromes: ", $count_of_2, "\n";
hope that helps :-)
perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'