in reply to Re: Bug or feature? s/// and the g option
in thread Bug or feature? s/// and the g option

As I understand it, /g is not a substitute for /sm

print is not a substitute for system. True, but obvious.

In fact, not only are they not equivalent, s, m and g are orthgonal.
s affects what . matches.
m affects what ^ and $ matches.
g affects the number of substitutions that will be made.

/g is sort of an iterator that lets you steadily step the matches in a string

No. You're thinking of m//g in void and scalar context. That's neither the case for m//g in list context nor for s///g.

my $x1 = $1 if $test =~ s/A/AA/g;

Off-topic, but my $var if ... is wrong. my has a run-time effect, so it shouldn't be executed conditionally.

Replies are listed 'Best First'.
Re^3: Bug or feature? s/// and the g option
by Krambambuli (Curate) on Oct 14, 2007 at 21:12 UTC
    Thank you, ikegami - all objections gratefully accepted.

    Turning back to the original question: so _should_ $1 contain something you could normally rely upon after a successfull s///g ?