Looks like most responders failed to notice you do not need the count of A/C/G/T in that string, but rather that you're goint to process several strings and count the number of A/C/G/Ts as the first character, second character, ...
Do drop the four separate variables and use a hash of arrays and make sure you declare your variables. That way you do not have to use the switch:
my @seq = split(//,$string); my $i = 0; foreach my $letter (@seq){ $counts{$letter}[$i]++ $i++; }
Then as others suggested you may want to get rid of the split. You may either use the subtring() as suggested or something like this:
my $i=0; $counts{$1}[$i++]++ while $string =~ /(.)/g;
Test for yourself what's quickest.
Jenda
Enoch was right!
Enjoy the last years of Rome.
In reply to Re: Iterating over string
by Jenda
in thread Iterating over string
by danielfortin86
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |