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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |