supriyoch_2008 has asked for the
wisdom of the Perl Monks concerning the following question:

Hi Perl Monks,

I am a beginner in perl programming. I prepared a perl program to count the number
of single letters and 3-letter words from a scalar variable $a. I got correct results
in counting single letters but wrong results for 3-letter words. Each 3-letter word occurs only
once in the string with a few spaces and 2 Ns but my program is showing inflated values for 3-letter
words due to overlapping effect of letters. I have given the wrong results that I got from the perl
program and also the correct results that I expect.

Of course, if you only want to match certain letters, then you're back to a regex. But in that case, I might still try stripping out all the stuff I don't want with tr//, followed by substr to break it into pieces.

Humm, you didn't actually use my code. (Not that the results would be visibly different.)

Your suggestion to remove the offending letters is broken if said letters can appear anywhere but the beginning and end of the string. "AAAGNTTT" should give "AAA", "TTT", but you're algorithm would give "AAA" and "GTT".

As 2teez points out, some three-letter words do occur more than once and a hash for counts rather than individual scalars is the way to go. You could use the glob function for initialization, saving a lot of fiddly, error-prone typing.

When putting a smiley right before a closing parenthesis, do you:

Use two parentheses: (Like this: :) )
Use one parenthesis: (Like this: :)
Reverse direction of the smiley: (Like this: (: )
Use angle/square brackets instead of parentheses
Use C-style commenting to set the smiley off from the closing parenthesis
Make the smiley a dunce: (:>
I disapprove of emoticons
Other