>>>>> "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/


Reply via email to