Oops! Sorry! Wrong section of the documentation. I meant to grab the
paragraph a little further down. Still in perlop, still in the Regexp
Quote-Like Operators section:
<docs>
The /g modifier specifies global pattern matching--that is, matching as
many times as possible within the string. How it behaves depends on the
context. In list context, it returns a list of the substrings matched by
any capturing parentheses in the regular expression. If there are no
parentheses, it returns a list of all the matched strings, as if there were
parentheses around the whole pattern.
In scalar context, each execution of m//g finds the next match, returning
true if it matches, and false if there is no further match. The position
after the last match can be read or set using the pos() function; see pos
in the perlfunc manpage. A failed match normally resets the search position
to the beginning of the string, but you can avoid that by adding the /c
modifier (e.g. m//gc). Modifying the target string also resets the search
position.
</docs>
So, to modify my reasoning a little (isn't post-rationalization great?!?)
that empty list I talked about gets populated with the matched strings (a
bunch of "a"'s in this case) and then that list is evaluated in scalar
context, yielding it's length. That length being the number of strings
matched.
Sorry about that, folks. I should post a "Cutting and Pasting Considered
Harmful." : )
Later,
Sean.