develooper Front page | perl.perl5.porters | Postings from November 2003

m/(?g)/ vs m/\G/g

Thread Next
From:
Dan Kogai
Date:
November 4, 2003 01:53
Subject:
m/(?g)/ vs m/\G/g
Message ID:
B8FA1118-0EAC-11D8-B16C-000393AE4244@dan.co.jp
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


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About