in reply to Re: substitute leading whitespace
in thread substitute leading whitespace

ikegami, maybe I'm misunderstanding your second reason, but I don't think it is correct, because it implies that, under the /g modifier, prior substitutions affect subsequent matches, but consider the following variant of the original example:

my $s = ' this is a string'; ( my $t = $s ) =~ s/(?<!\w)\s/X/g; print $t, $/; __END__ XXXthis is a Xstring
If I understood your second reason correctly, according to it the printout would have been:
X Xthis is a Xstring
because after the first substitution the second space no longer matches the first part of the s///.

the lowliest monk

Replies are listed 'Best First'.
Re^3: substitute leading whitespace
by ikegami (Patriarch) on Jun 10, 2005 at 14:59 UTC

    You've just demonstrated my first point. My second point explained why the regexp wouldn't work even in the absense of the behaviour.

    Less abstractly, I was tring to explain that matching the beginning of the string (^ when not under /m) is useless under </code>/g</code>. It's the same as if /g wasn't there. I rephrased my post to this effect.

      You've just demonstrated my first point. My second point explained why the regexp wouldn't work even in the absense of the behaviour. Less abstractly, I was tring to explain that matching the beginning of the string (^ when not under /m) is useless under </code>/g</code>.

      Heh, that's a neat trick! First, delete the text a post refers to, and then offer an (unfalsifiable) interpretation of what that post is saying. Cool!

      the lowliest monk