Why does my Perl regex cause an infinite loop?

($marker_re|\Z)/gs ) { print "---\n$1\n"; pos $text -= length $2; } __DATA__ foo one { one1 one2 one3 foo two { two1 two2 two3 two4 } that was the second one foo three { 3 foo 3 foo 3 foo 3 foo foo foo four{} Output: one1 one2 one3 --- two1 two2 two3 two4 } that was the second one --- 3 foo 3 foo 3 foo 3 foo foo --- }.

($marker_re|\Z)/gs ) { print "---\n$1\n"; pos $text -= length $2; } __DATA__ foo one { one1 one2 one3 foo two { two1 two2 two3 two4 } that was the second one foo three { 3 foo 3 foo 3 foo 3 foo foo foo four{} Output: --- one1 one2 one3 --- two1 two2 two3 two4 } that was the second one --- 3 foo 3 foo 3 foo 3 foo foo --- }.

About, yes. I'm looking for everything after the { and before the next foo. – Paul Nathan Aug 18 '09 at 22:18 That works.

Without the pos $text -= 3, it returns the first and the last. I'm afraid I'm pretty confused about why your solution worked and what was wrong with mine. Thoughts?

– Paul Nathan Aug 18 '09 at 22:33 Looking for the (?:foo|\Z) advances pos $text by the length of foo if there is a foo. Therefore, the next match starts after the next foo unless pos $text is reset to a position before the next foo which is three characters before the current position. If you have already hit the end of the string, this does not matter.

– Sinan Ünür Aug 18 '09 at 22:42 1 @Sinan: I notice that if there is a my $foomatic, the regex matches the 'foo'. I modified my regex to have \bfoo\b. :-) thanks a lot for the help.

– Paul Nathan Aug 18 '09 at 23:25.

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