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? :)
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? :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@words = split(/[\s.,;:\'\"\\\/\`\~
foreach(@words) {
$twocharwords++ if length($_)==2;
$threecharwords++ if length($_)==3;
}
print "two char word count: $twocharwords, three char word count: $threecharwords\n";