On Thu, Feb 14, 2008 at 03:51:21PM -0700, Thom Boyer wrote:
> S02 provides this example for treating curlies literally in a quoted string:
>
>     qq:!c "Here are { $two uninterpolated } curlies";
>
> But can I escape them with a backslash? I was surprised that I couldn't 
> find anything in S02 which said either yes or no. Perhaps this falls under 
> the heading of "anything not specifically defined in the synopses acts just 
> like it did in Perl 5", and I should just shut up.

Well, it ends up being the same as Perl 5 in the degenerate cases, but
that's far from an adequate reason to shut up.

> In the description of the :q (aka :single) adverb, there is mention of the 
> fact that you can escape the quoting character, as in
>
>     Q :q "The ubiquity of \"air quotes\" is really annoying to me";
>
> and the description of :b (aka :backslash) indicates that it activates the 
> usual substitutions on \a, \b, \t, \n, \f, \r, and \e,
>
>     Q :b "Here's a BEEP \a and a newline \n;
>
> but I can't find any discussion of whether "\p" is legal (presumably 
> identical to "p") or lexically illegal ("unrecognized escape sequence in 
> string literal"). And in that example, by p I mean any character p for 
> which S02 doesn't define the meaning of \p.

The default depends on whether the basic intent is double or single
quoting, basically.  See my last S02 changes.

> In particular, there's no mention of whether \ can be used to escape $, @, 
> %, &, or {. I would _assume_ that
>
>     "Here are \{ $two uninterpolated \} curlies";
>
> means the same as the first example, above, but I can't find anything that 
> says so.

Does now.  :)

> So, I would hope that
>
>     $fruit = 'apple';
>     $number = 7;
>     $money = 'peso';
>     say "set A = \{ $fruit, {$number+1}, \$money \}";
>
> actually says
>
>     set A = { apple, 8, $money }
>
> Does it?

Well, actually, it says:

    Variable "$fruit" requires predeclaration or explicit package name

:)

> And, do I really need to backwhack the final (closing) curly?
>
>     say "set A = \{ $fruit, {$number+1}, \$money }";

There it is optional, because } does not cause interpolation.
(Though if the delimiters were curlies, the opener and closer would
have to be backslashed the same, to avoid throwing off the bracket
counter.)  In any case, double quoting removes the backslash from
any non-alphanumeric character.  Single quoting tends to preserve them.

Larry

Reply via email to