Count The Appearence Of Certain Chars
Join the DZone community and get the full member experience.Join For Free
Count the appearence of certain chars using regular expression query and using perl's string-operator
#!/usr/bin/perl # Count the appearence of certain chars using regular expression query # $string="MNVDPFSPHSSDSFAQAASPARKPPRGGRRIWSGTREVIAYGMPASVWRDLYYWALKVSWPVFFASLAALFVVNNTLFALLYQLGDAPIANQSPPGFVGAFFFSVETLATVGYGDMHPQTVYAHAIATLEIFVGMSGIALSTGLVFARFARPRAKIMFARHAIVRPFNGRMTLMVRAANARQNVIAEARAKMRLMRREHSSEGYSLMKIHDLKLVRNEHPIFLLGWNMMHVIDESSPLFGETPESLAEGRAMLLVMIEGSDETTAQVMQARHAWEHDDIRWHHRYVDLMSDVDGMTHIDYTRFNDTEPVEPPGAAPDAQAFAAKPGEGDARPV"; $neg = ($string =~ tr/[DE]//); $pos = ($string =~ tr/[RK]//); $his = ($string =~ tr/[H]//); $total = $pos+$his-$neg; $totalNoHis = $pos-$neg; print "NEG = $neg ; POS = $pos ; HIS = $his; TOT = $total (without HIS = $totalNoHis)\n";
Opinions expressed by DZone contributors are their own.