|Do you know where your variables are?|
Re: Is it possible to get all tetra words with correct starting position using a better code within a loop?by GrandFather (Sage)
|on Nov 22, 2012 at 09:28 UTC||Need Help??|
There are many issues with your code. First off though, always use strictures (use strict; use warnings; - see The strictures, according to Seuss). You use warnings, but strict is at least as important for catching errors. As another general coding tip: don't use the same name for multiple variables. In your sample code you use both $pro and @pro as well as @tetra and $tetra.
Although it is often a good idea to give a manifest constant a name so the intent of the constant is clear, using a variable for 1 called $one adds no information and is likely to cause confusion just because there seems no reason to use the variable.
Your "uninitialized value" variable warning is because you use @+ before the first regular expression match.
You aren't getting the number of iterations in the loop you expect because you update @pro within the loop. That is almost always a bad idea.
There are many ways to skin this cat. One trick is to use a look ahead match and take advantage of the fact that the regular expression engine doesn't allow successive matches at the same position. Consider:
True laziness is hard work