in reply to Iterating over string

The thing to look out for is doing away with the new-line chars as sequence data can be spread across a large number of lines, make it a habit to localize scope for your variables and turn the strictures on, that is a good programming habit, also, check perltidy because, your code has to be readable in order for it to be maintainable later and frankly, your coding style seems good with these indentation however, you skipped to add spaces at "foreach$letter(@seq)"...
use strict; use warnings; my %counts; my @seq; local $/=''; while(<DATA>){ chop; s/\n//; @seq = split ''; } foreach my $element (@seq){ #count for each DNA base or group foreign letters $element =~/[agct]/gi ? $counts{$element}++ : $counts{'N'}++; } use Data::Dumper; print Dumper(\%counts); __DATA__ agcttgtc agtccxffhhhh
One final suggestion/exercise, check Benchmark to compare speeds of segments of code in order to decide which one of these proposed approaches is fast(er|est) and pick it up. Though I believe, and would like to be corrected if otherwise, that switch statements are computationally expensive...


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.