MentalAbsence has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Escape Quote-Like Operators
by BrowserUk (Patriarch) on Sep 11, 2013 at 17:10 UTC | |
|
Re: Escape Quote-Like Operators
by SuicideJunkie (Vicar) on Sep 11, 2013 at 18:04 UTC | |
|
Re: Escape Quote-Like Operators
by tobyink (Canon) on Sep 11, 2013 at 17:50 UTC | |
|
Re: Escape Quote-Like Operators
by kennethk (Abbot) on Sep 11, 2013 at 18:37 UTC | |
by Anonymous Monk on Sep 11, 2013 at 20:24 UTC | |
by kennethk (Abbot) on Sep 11, 2013 at 21:08 UTC | |
|
Re: Escape Quote-Like Operators (fat comma)
by tye (Sage) on Sep 12, 2013 at 01:37 UTC | |
by LanX (Saint) on Sep 12, 2013 at 10:15 UTC | |
|
Re: Escape Quote-Like Operators
by Not_a_Number (Prior) on Sep 11, 2013 at 19:52 UTC |