For those of you (I admit I am one) who want to write s/this/that/sexgizmo, I'm sorry, I've not named this modifier /z. Rather, it is /G (unless Perl5-Porters says nay).

Here's how it's useful:

while (/name:\s*(\w+)\s+age:\s*(\d+)/g) { my ($name, $age) = ($1,$2); # ... } ### becomes while (my ($name, $age) = /name:\s*(\w+)\s+age:\s*(\d+)/G) { # ... }
What the /G modifier does is FORCE scalar context on a /.../g (global) match (so that pos() can be set accordingly), yet allow you to do this global match in list context. Now, if you've ever done a global match in list context, you know that it goes through all the matches. That means you can't write:
while (my ($name, $age) = /name:\s*(\w+)\s+age:\s*(\d+)/g) { # ... }
and expect it to work how you'd like. So, use /G there and your problems are solved.

Look for this new modifier in Perl 5.8!

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;


In reply to New regex modifier! by japhy

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.