Perl: Multiple global “or”-separated regex conditions in while block leads to an infinite loop?

The thing is that there's a hidden value associated with each string not with each match that controls where a g match will attempt to continue, and accessible through pos($string) What happens is: pos($hivar) is 0 this matches at position 0 and resets pos($hivar) to 4. The second match isn't attempted because the or operator is already true $& becomes "this" and gets printed pos($hivar) is 4 this fails to match because there's no "this" at position 4 or beyond. The failing match resets pos($hivar) to 0 that matches at position 6 and resets pos($hivar) to 10 $& becomes "that" and gets printed pos($hivar) is 10 this fails to match because there's no "this" at position 10 or beyond.

The failing match resets pos($hivar) to 0 that matches at position 6 and resets pos($hivar) to 10 $& becomes "that" and gets printed and steps 4 and 5 repeat indefinitely Adding the c regex flag (which tells the engine not to reset pos on a failed match) solves the problem in the example code you provided, but it might or might not be the ideal solution to a more complex problem.

The thing is that there's a hidden value associated with each string, not with each match, that controls where a /g match will attempt to continue, and accessible through pos($string). What happens is: pos($hivar) is 0, /this/ matches at position 0 and resets pos($hivar) to 4. The second match isn't attempted because the or operator is already true.

$& becomes "this" and gets printed. Pos($hivar) is 4, /this/ fails to match because there's no "this" at position 4 or beyond. The failing match resets pos($hivar) to 0.

/that/ matches at position 6 and resets pos($hivar) to 10. $& becomes "that" and gets printed. Pos($hivar) is 10, /this/ fails to match because there's no "this" at position 10 or beyond.

The failing match resets pos($hivar) to 0. /that/ matches at position 6 and resets pos($hivar) to 10. $& becomes "that" and gets printed.

And steps 4 and 5 repeat indefinitely. Adding the c regex flag (which tells the engine not to reset pos on a failed match) solves the problem in the example code you provided, but it might or might not be the ideal solution to a more complex problem.

2 really well explainned, cookie for u. – Prix Jun 26 '10 at 4:28 Indeed. Well put.

Thank you! – Tom the Junglist Jun 26 '10 at 23:36.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions