Link to home
Start Free TrialLog in
Avatar of petepalmer
petepalmer

asked on

Counting diagraphs and trigraphs in Perl

Hi,
   I have a string in perl say    "hh bbb. rt irr"

   I'm looking for some way of going through that string and counting how many three letter words there are and how many two letter words. punctuation should be ignored....


 Any takers? :)


Avatar of rj2
rj2

$text="hh bbb. rt irr";
@words = split(/[\s.,;:\'\"\\\/\`\~\!\@\#\$\%\^\& \*\(\)\_\- \+\+\[\]\{\}\?]+/,$text);
foreach(@words) {      
      $twocharwords++ if length($_)==2;
      $threecharwords++ if length($_)==3;
}
print "two char word count: $twocharwords, three char word count: $threecharwords\n";
ASKER CERTIFIED SOLUTION
Avatar of jmcg
jmcg
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial