On Jun 25, Sally said:

>when evaluating strings what exactly does /g do at the end of a lot of
>evaluation expressions eg:
>
>$string =~ /(.)/g

The /g modifier is for regexes only (not strings in general).  It is
documented in 'perlre' and probably 'perlop' as well.

It tells Perl that the regex is to match, and then REMEMBER WHERE THE
MATCH ENDED, so that it can start there the next time /.../g is used.

The most common uses of it are:

  # all at once...
  @all_matches = $string =~ /(pattern)/g;

and

  # one at a time
  while ($string =~ /(pattern)/g) {
    # ...
  }

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **

Reply via email to