If you want to pretty indent the heredoc contents so that they are indented within the if clause, you can get most of the way there with the following code:

if (1) { (my $sOutput = <<'OUTPUT') =~ s/^\s+|\n(?!\s+\n)//gm; Today is Monday, my favorite day of the week. It is my favorite day because Jerry said "Monday is the best day of the week". Tuesday is my second-favorite day. Why can't all days be as great as Monday? Who knows. This is a second paragraph. OUTPUT print "$sOutput\n"; }

which outputs

Today is Monday, my favorite day of the week.It is my favorite day bec +ause Jerry said "Mondayis the best day of the week". Tuesday is my s +econd-favorite day.Why can't all days be as great as Monday? Who kno +ws. This is a second paragraph.

You'll still need to keep OUTPUT at the start of the line (unless you chose to use whitespace in your end of here-doc marker as JavaFan suggests below), but at least you can indent the remainder of the text. The regular expression s/^\s+|\n(?!\s+\n)//gm removes leading whitespace on all lines. It merges together all lines that have only 1 newline between them and collapses a run of blank lines into a single newline. If instead you want to keep the line breaks exactly as shown in the heredoc, you can use a slightly different regular expression: s/^[^\S\n]+//gm, which results in the output:

Today is Monday, my favorite day of the week. It is my favorite day because Jerry said "Monday is the best day of the week". Tuesday is my second-favorite day. Why can't all days be as great as Monday? Who knows. This is a second paragraph.

For more information and other neat tricks you can do with here-documents, see perlop and search for "here-doc".

Best, beth

Update 1: added example that preserves line breaks.

Update 2: corrected my post with a parenthetical comment refering to JavaFan's post below.


In reply to Re: best way to print paragraphs of text by ELISHEVA
in thread best way to print paragraphs of text by keiusui

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.