The first parentheses is always stored only in $1 with or without the g switch. You can either use
while(<DATA>) { while (1) { last if not /(\w+)/g; print $1,"\n"; } }
or
while(<DATA>) { my @ar= /(\w+)/g; print @ar,"\n"; }
As you can see, the g switch works differently in scalar and array context. Read perlre to get the details. And you might add "use warnings;" to your scripts
In reply to Re: global regex
by jethro
in thread global regex
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |