in reply to New regex modifier!

Why doesn't the /g modifier-ed match just return the matches? It would be the empty list, false, if it didn't match; or have it detect whether called in scalar or list context?

Replies are listed 'Best First'.
Re: Re: New regex modifier!
by japhy (Canon) on Sep 12, 2001 at 02:16 UTC
    In list context, //g returns all the matches. This new modifier will only match once, but the next time, it'll start attempting to match where the last one stopped. It's like doing:
    while (/pattern/g) { my ($x, $y, $z) = ($1, $2, $3); # ... }
    except that you can combine the regex and the assignment.

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

      Ah, now I get it. It doesn't "force scalar context" because it's returning a list, but makes it match once like /g does in scalar context.