http://qs321.pair.com?node_id=11125465


in reply to Here documents in blocks

Something like this ?

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11125451 use warnings; sub indent { my $text = shift; $text =~ s/^\s//gm until $text =~ /^\S/m; return $text; } if (1) { print indent(<<""); Here is some test text with plenty of space and even an indented line at the start }

Outputs:

Here is some test text with plenty of space and even an indented line at the start

Replies are listed 'Best First'.
Re^2: Here documents in blocks
by LanX (Saint) on Dec 19, 2020 at 20:13 UTC
    > print indent(<<"");

    The empty line marker is dangerous, at least if your editor doesn't highlight trailing white-space (mine does)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      It's just a tradeoff between danger and beauty :)

      Personally I put the HERE-IS block at the left hand edge, and skip the whole "indent" thing.
      (A what (indent) you see, is what you get.)

        > Personally I put the HERE-IS block at the left hand edge, and skip the whole "indent" thing. (A what (indent) you see, is what you get.)

        me too, mostly at the end of a sub.

        If I need a template, then it'll normally also merit a sub.

        sub html_admin { my($user_number)=@_; my $HTML_restricted = ""; $HTML_restricted = <<"__HTML__" if $user_number == 20; <tr> <td class="someClass">Restricted</td> </tr> __HTML__ return << "__HTML__"; <table> <tr> <td class="someclass" style="text-align:center">Some Content +</td> </tr> $HTML_restricted </table> __HTML__ }

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery