hi guyz..how r u? I am facing a problem with a simple Perl script. I want my code to calculate the length/number of letters present in a text file (which is the input). But it should skip the line starting with '>'. The input used is given below (also attached).
>blast1
CGTTAC
GGCTAC
I wrote the following code:
#!usr/bin/perl -w
print "Print your file name with location\n";
$dnafile=<STDIN>;
chomp $dnafile;
open (DNA, $dnafile);
while ($dna=<DNA>) {
chomp ($dna);
if ($dna=~/^(A|C|G|T)/) {
@dna=split ('', $dna);
$length= length ($dna);
print "Length is $length\n";
}
}
But it shows the output like this:
Length is 6.
Length is 6.
But I want it Length is 12 (because when I use an input text file with hundreds of lines and letters, it would be harder to count. But the format of the text file will remain same.
It would be great also if you could point out my mistakes here, thus helping me to learn from my mistakes.
Many thanks in advance..