Here's how it's useful:
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 (/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) { # ... }
and expect it to work how you'd like. So, use /G there and your problems are solved.while (my ($name, $age) = /name:\s*(\w+)\s+age:\s*(\d+)/g) { # ... }
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:??;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: New regex modifier!
by John M. Dlugosz (Monsignor) on Sep 12, 2001 at 01:53 UTC | |
by japhy (Canon) on Sep 12, 2001 at 02:16 UTC | |
by John M. Dlugosz (Monsignor) on Sep 12, 2001 at 04:10 UTC |