Don't ask to ask, just ask | |
PerlMonks |
While behaviorby SavannahLion (Pilgrim) |
on Feb 15, 2014 at 03:34 UTC ( [id://1075017]=perlquestion: print w/replies, xml ) | Need Help?? |
SavannahLion has asked for the wisdom of the Perl Monks concerning the following question: I was knocking my head against a bug in my code when I came across Perlish behavior I don't really understand. I reduced the code to the bare minimum to best show the behavior.
The above code will output indefinitely:
Now, if we modify the code just a little bit, we get the following code and behavior, which is what I wanted:
The above will output what I expect:
To get it out of the way, someone might say why don't I do the below instead? The behavior is the same as above. To avoid dirty details, yes, that's true. I just want to preserve $_ deeper within the while{} block
Can someone explain why the first code sample doesn't work as I would expect? The only thing I can think of is that the RegEx pointer isn't being preserved on each iteration, but I don't understand why....
Back to
Seekers of Perl Wisdom
|
|