Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Count The Appearence Of Certain Chars

DZone's Guide to

Count The Appearence Of Certain Chars

·
Free Resource
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";

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}