[Tokyo.pm] m/(?g)/ vs m/\G/g

Dan Kogai dankogai @ dan.co.jp
2003年 11月 4日 (火) 03:53:20 CST


Porters,

Utashiro-san (Who translated the Owl Book to Japanese) has reported to 
Tokyo.pm ML that

   perl -e '$_=12345; while (/(?g)\d/) {print "$&\n";}'

Goes into an infinite loop on the perl that comes with Panther.  
Watanabe-san (the author of Jperl) further tracked down the symptom and 
found the (?g) stopped working since Perl 5.8.  Utashiro-san suspects 
that (?imsx-imsx) does not contain "g" so the code above remained an 
(accidental,) undocumented feature till Perl 5.8 closed the loophole.

FYI

   perl -e '$_=12345; while (/\G\d/g) {print "$&\n";}'

Works just fine.  I just want to know if we eliminated (?g) on purpose 
(IMHO it should simply croak.  So far it appears to be a no-op).

perldoc perlre
>        The "\G" assertion can be used to chain global matches
>        (using "m//g"), as described in "Regexp Quote-Like Opera-
>        tors" in perlop.  It is also useful when writing
>        "lex"-like scanners, when you have several patterns that
>        you want to match against consequent substrings of your
>        string, see the previous reference.  The actual location
>        where "\G" will match can also be influenced by using
>        "pos()" as an lvalue: see "pos" in perlfunc. Currently
>        "\G" is only fully supported when anchored to the start of
>        the pattern; while it is permitted to use it elsewhere, as
>        in "/(?<=\G..)./g", some such uses ("/.\G/g", for example)
>        currently cause problems, and it is recommended that you
>        avoid such usage for now.

methinks that Utashiro-san's (?g) falls into "such usage" that should 
be avoided....

Dan the Irregularly Expressing Man




Tokyo-pm メーリングリストの案内