Uri, Thanks for this contribution. I didn't know that. So, please correct me if I'm wrong:
The first pattern search starts in the beginning of the string, then if it match, it returns TRUE and it go inside the While Loop. Then, when it finishes the Loop, continues from the last pattern matched and so on. Is it correct? Thanks in advance, Ary On Sat, Oct 30, 2010 at 5:12 AM, Uri Guttman <u...@stemsystems.com> wrote: > >>>>> "J" == Jatin <daveyja...@gmail.com> writes: > > J> On Saturday 30 October 2010 01:26 PM, Uri Guttman wrote: > > >> wrong. in this case in scalar context, it does stop after a match. the > >> difference is that the starting point for the NEXT loop will be after > >> the match. so it will keep matching until the end of the string. hence, > >> it will always stop and no infinite loop. > >> > J> [Jatin] And hence /g is needed to stop the matching when the matching > J> is used in scalar context. > > no. /g just makes the match START at the end of the last match. this > forces it to scan the string to the end so the LOOP will end. /g has > nothing to do with stopping anything itself. it just sets the starting > point of the match. you can do a single match in scalar context without > /g but it will not scan forward for the next time. this is what caused > your infinite loop. /g is very useful in scalar context when used in a > loop. > > uri > > -- > Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com-- > ----- Perl Code Review , Architecture, Development, Training, Support > ------ > --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com--------- > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >