Syntactic Confectionery Delight | |
PerlMonks |
Re^3: Counting wordsby Laurent_R (Canon) |
on Nov 05, 2017 at 00:17 UTC ( [id://1202770]=note: print w/replies, xml ) | Need Help?? |
Hi bisimen,
the solution suggested by toolic uses regular expressions to cut the string into segments of $length (2, in this case) letters. Regular expressions are a very powerful feature of Perl that you really need to learn at some point. However, assuming you don't know regular expressions yet, this is another way you could do it, which might be easier for you to understand: This creates the following counters in the %cnt hash: Note that this is not the way I would do it, but it is hopefully easier to understand for you, and one of Perl's favorite mottoes is: TIMTOWTDI, i.e. there is more than one way to do it. Update: Using unpack would most probably be more efficient. Here I only wanted to show a possible process step by step.
In Section
Seekers of Perl Wisdom
|
|