in reply to Re: Regex infinite loop?
in thread Regex infinite loop?
I think I need to give everyone more to go on, so here it is. My matching code looks like the following.
while (content =~ m%One(.*?)three(.?)five\s+six(.*?)this%gs) { $var1 = $1 ; $var2 = $2 ; $var3 = $3 ; print "$var1\t$var2\t$var3\n" ; }
It gives me output that looks like you would expect, say, for example:
two four sevenWhen the code hangs, it prints out the same thing, but then nothing more.
Now, I've made the following change in keeping with your suggestion.
while (content =~ m%One(.*?)three(.?)five\s+six(.*?)this%gs) { print(STDERR "[", pos($content), "]") ; $var1 = $1 ; $var2 = $2 ; $var3 = $3 ; print "$var1\t$var2\t$var3\n" ; }
I'm relatively new to PERL and not a professional coder, so I'm not sure what this is supposed to produce, but here's an example of what I am getting.
[ two four seven 48430]
On another match, however, it gives me:
[48226] three more numbers
When it hangs, it gives me the following.
[50757] first three numbers second three numbers third three numbers [51826][52896]
Does this help with understanding the problem?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Regex infinite loop?
by moritz (Cardinal) on Oct 16, 2008 at 19:30 UTC | |
by Ninth Prince (Acolyte) on Oct 17, 2008 at 00:54 UTC | |
|
Re^3: Regex infinite loop?
by ikegami (Patriarch) on Oct 16, 2008 at 20:45 UTC |