DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Count The Appearence Of Certain Chars

03.02.2007
| 2792 views |
  • submit to reddit
        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";