in reply to Quote and Quote-like Operators

I agree with the other comment that heredocs are not ugly, and are often the best way of including multi-line strings in your code (such as big chunks of SQL).

It might be worth mentioning how heredocs can be stacked:

use Test::More; use Example::HTML::Reformatter qw/reformat/; is(reformat(<<'IN'), <<'OUT', 'HTML was reformatted'); <html><head ><title>Foo</title><body></html> IN <html> <head> <title>Foo</title> </head> <body> </body> </html> OUT done_testing(1);

Another thing worth mentioning might be how when bracketting characters are used to quote strings, they must balance.

my $str = q{Foo{the following curly does not end the quote}but the nex +t one does};

Replies are listed 'Best First'.
Re^2: Quote and Quote-like Operators
by Xiong (Hermit) on Dec 16, 2011 at 11:58 UTC

    I'm sorry; I don't understand your heredoc-stacking example. Would you be able to offer a use case compelling to the Perl newcomer?

    Let's refrain from discussing nesting delimiters in generic quotes; I'm not sure I'd want to encourage it. To the newcomer, I'd rather emphasize the value of choosing delimiters wisely.

    Full details are always available in perlop. I'd hoped to avoid mentioning usage such as q][] in a basic introduction. Thank you for your comments.

    Feste: Misprison in the highest degree. Lady, cucullus non facit monachum. That's as much to say as, I wear not motley in my brain....

      I thought the example I provided, where you want to pipe some multi-line input data through a function, and compare the result to an expected set of multi-line output data, is a fairly realistic example of where stacking heredocs might be used. I won't claim to use stacked heredocs on a frequent basis, but I have used them from time to time, and have seen them used by others.

      I use it in this test file for example:

      http://api.metacpan.org/source/TOBYINK/XML-LibXML-PrettyPrint-0.002/t/03indent.t
Re^2: Quote and Quote-like Operators
by JavaFan (Canon) on Dec 16, 2011 at 13:41 UTC
    If they would be stacked, the first terminator would be OUT, and the latter IN, as a stack is "first in, last out". In this example, there isn't anything magic going on, there are just two of them. No "stacking" involved.
      The word "stack" is used in <<EOF.