I've had a look around, but can't find whether this is a known issue or I'm doing something stupid. Basically I'm trying to extract a series of tokens from a string. Classic use of the m/\G.../gc construct. I have a loop as such:
my $a = 'first second ...other non-\w char groups...'; my @s; while (... not finished string ...) { if ($a =~ /\G(\w+) ?/gc) { push @s, $1; } elsif ... other stuff not important }
Now most of the string happens to be \w+ type tokens, so I thought it might be a useful performance optimisation to try and grab a whole heap of matches at once as such:
while (... not finished string ...) { if (my @m = ($a =~ /\G(\w+) ?/gc)) { push @s, @m; } elsif ... other stuff not important }
Now the matches work correctly, but it doesn't update the internal pos(),\G marker, so the next match occurs at the same place again (eg infinite loop). I also tried something like:
while (... not finished string ...) { if (my @m = ($a =~ /\G(?:(\w+) ?)+/c)) { push @s, @m; } elsif ... other stuff not important }
But it only returns the last match and doesn't appear to update pos(),\G either. So a couple of questions. Is there a way to grab multiple matches with m/\G.../gc? Am I dreaming that any of this might be a performance win? (what about long strings where $' has already been referenced so there's lots of string copying to do after each match?) Rob

In reply to m/\G..blah../gc matching in list context by robmueller

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.