in reply to Tokenizing and qr// <=> /g interplay

For starters, perlop says that the qr operator looks like this: qr/STRING/imosx - g isn't allowed.

Using $stream =~ /$regex/g still only compiles the regex once as the way that perl interpolates the $regex into a match operator should handle this for free (as in CPU time).

Replies are listed 'Best First'.
Re^2: Tokenizing and qr// <=> /g interplay
by skyknight (Hermit) on Apr 23, 2005 at 15:44 UTC
    OK, that seems to make sense... So presumably the following idiom is the right way to go about things...
    while ($stream =~ /$regex/g) { print "token: $1\n"; }