Is there a way to cause letters that begin quote-like operators such as m, s, qq, qr, and friends to be treated as barewords as opposed to the beginning of a quoted or regular expression string? If you look at the following nonsensical example:

$_ = '12'; s/(\d+)/($1 > 10)?m:n/e;

The intent is to replace the number in $_ with either 'm' or 'n', but Perl complains:

"Search pattern not terminated..."

because it thinks that 'm:' is the start of a regular expression match operator. Of course, I can quote the 'm' and everything works fine, but unfortunately this is for golf and I'd like to be able to leave off the quotes if possible to save characters. Is there a way to escape the 'm' or cause it not to be treated as an operator at a cost of fewer than the two characters it takes to quote it? Thanks for your thoughts!


In reply to Escape Quote-Like Operators by MentalAbsence

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.