If Perl were to guess that "#" indicates a comment, it'll introduce a paradox. Consider

s{foo}{ bar #}xe }

If Perl stops at the second "}", then the replacement expression is not code and "#" are not comments and Perl should have stopped at the first "}".

If Perl stops at the first "}", then the replacement expression is code ("e") and "#" are comments ("x") and Perl should have stopped at the second "}".

Perl needs to find the end of the operator to find the "e" and "x" flags. To find the end of the operator, Perl initially treats the expression as a replacement string. When the "e" flag is found is the replacement string is reparsed as code. Only then does "x" have any meaning.

Perl 6 fixes this by placing the flags before the replacement expression.


In reply to Re: Commented braces in Code by ikegami
in thread Commented braces in Code by sanPerl

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.