20:29: beretboy: s/ttt/tt/g; 20:34: alienhuman: /o would make that more efficient :)
Cool. Well this bug was unknown to me when a discussion of the /o modifier came up. (Still around in 5.6.1 AS630) I whipped together a little example and discovered unknowing exactly the same bug (crazyinsomniac mentioned this thread but I didn't read it until afterwards, honest :)

At first glance though it seemed to be even wierder.

$\="\n"; $_='aaa'; my $c='a'; print "$c:$_"; print "------"; print "$c:$_" while s/$c/$c++/oe; print "------"; print "$c:$_";
Now by all rights this should produce the following sequence:
a:aaa ------ a:aaa b:baa c:bca d:bcd ------ e:bcd
But instead produces:
a:aaa ------ b:aaa ------ b:aaa
So now if we change the statement so its ++$c we get
a:aaa ------ b:baa c:caa d:daa e:eaa f:faa .....
Which is unlike what might be expected (even considering the /o bug) until you think about it for a second. With preincremnt The first match succeded ('aaa'=~/a/) and was replaced by itself, then $c was incremented. The second match fails ('aaa'=~/b/) and the loop stops.

So with post increment we get a match ('aaa'=~/a/) but now the replacement happens with the incremented value, so the second match ends up being ('baa'=~/b/) which is then replaced by 'c'.

I suppose this all is obvious, but I thought it was a weird enough example to add to your bug report.

Oh and you can blame:

21:45: alienhuman: /o would make that more efficient :)
:-)

Yves / DeMerphq
--
Have you registered your Name Space?


In reply to Re: 'o' modifier clarification needed by demerphq
in thread 'o' modifier clarification needed by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.