in reply to Iterating over string
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...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
|
|---|