Re: String Literals, take 2

[email protected] ("Joseph F. Ryan") Mon, 02 Dec 2002 17:12:06 -0500
Newsgroups perl.perl6.documentation
Message-ID <[email protected]>
Luke Palmer wrote:

>>=head3 Embedding Interpolated Strings
>>
>>It is also possible to embed an interpolating string within a non-
>>interpolating string by the use of the \qq{} construct.  A string
>>inside a \qq{} constructs acts exactly as if it were an interpolated
>>string.  Note that any end-brackets, "}", must be escaped within the
>>the \qq{} construct so that the parser can read it correctly.
>>    
>>
>
>I don't remember this from anywhere.  Where was this discussed?
>

http://www.perl.com/pub/a/2001/05/03/wall.html#rfc 226: selective 
interpolation in single quotish context.

>Object methods I<are> object members.  All attributes are private, but
>accessors are auto-generated for you (if you don't say otherwise).  So
>I don't think parens should be required.
>

Larry seems to disagree:
http://www.perl.com/pub/a/2001/05/03/wall.html#rfc 252: interpolation of 
subroutines

>>=head3 Embedding non-interpolated constructs: C<\q{}>
>>
>>Similar to embedding an interpolated string within a non-interpolated
>>string, it is possible to embed a non-interpolated string within a
>>interpolated string with \q{}.  Any characters within a \q{} construct
>>are treated as if they were in an non-interpolated string.
>>    
>>
>
>And this is waaay down here away from \qq{}... why?
>

A sort of segregationist measure; I tried to keep single quote
behaivors confined to a single quote section, and double quote
behaviors to a double quote section.  Perhaps some sort of
reorganization is in order?

>>=head2 Special Quoting
>>
>>=head3 Here-Docs
>>
>>A line-oriented form of quoting is based on the shell "here-document"
>>syntax.  Following a << you specify a string to terminate the quoted
>>material, and all lines following the current line down to the
>>terminating string are the value of the item. The terminating string
>>may be either an identifier (a word), or some quoted text. If quoted,
>>the type of quotes you use determines the treatment of the text, just
>>as in regular quoting. An unquoted identifier works like double quotes.
>>The terminating string must appear by itself, and any preceding or
>>following whitespace on the terminating line is discarded.
>>
>>=over 3
>>Examples:
>>
>>    print << EOF;
>>    The price is $Price.
>>    EOF
>>
>>    print << "EOF"; # same as above
>>    The price is $Price.
>>    EOF
>>
>>    print << "EOF"; # same as above
>>    The price is $Price.
>>        EOF
>>
>>    print << `EOC`; # execute commands
>>    echo hi there
>>    echo lo there
>>    EOC
>>
>>    print <<"foo", <<"bar"; # you can stack them
>>    I said foo.
>>    foo
>>    I said bar.
>>    bar
>>
>>    myfunc(<< "THIS", 23, <<'THAT');
>>    Here's a line
>>    or two.
>>    THIS
>>    and here's another.
>>    THAT
>>    
>>
>
>You didn't mention that <<'THAT' doesn't interpolate.
>
>  
>
>>If you use a here-doc within a delimited construct, such as in s///eg,
>>    
>>
>
>Ummm, s:e//$()/
>

Silly me :)

>
>And that's interesting, as the rule might not still hold.
>  
>

Very true.

>>the quoted material must come on the lines following tvhe final
>>delimiter. So instead of:
>>
>>=over 3
>>    s/this/<<E . 'that'
>>    the other
>>    E
>>    . 'more '/eg;
>>=back
>>
>>you have to write
>>
>>=over 3
>>    s/this/<<E . 'that'
>>    . 'more '/eg;
>>    the other
>>    E
>>=back
>>
>>Also note that with single quoted here-docs, backslashes are not
>>special, and are taken for a literal backslash, a behaivor that is
>>different from normal single-quoted strings.
>>    
>>
>
>Yes.  Shoulda mentioned that a long time ago, IMO.
>

Yeah, yeah, yeah.



Thanks for responding,

Joseph F. Ryan
[email protected]