G'day Corion,

++ For the technique.

However, there is a problem with that code as written:

$ cat pm_1185726_heredoc_pod.pl my $str = <<=cut; =head2 Some documentation =cut $
$ perl -MO=Deparse pm_1185726_heredoc_pod.pl Use of bare << to mean <<"" is deprecated. Its use will be fatal in Pe +rl 5.28 at pm_1185726_heredoc_pod.pl line 1. Can't modify scalar in scalar assignment at pm_1185726_heredoc_pod.pl +line 1, near "cut;" pm_1185726_heredoc_pod.pl had compilation errors. my $str = "" = 'cut'; $

Changing the <<=cut; to either <<"=cut"; or <<'=cut'; fixes the problem.

$ perl -MO=Deparse pm_1185726_heredoc_pod.pl my $str = "\n=head2 Some documentation\n\n"; pm_1185726_heredoc_pod.pl syntax OK

[The POD is rendered fine in all cases with: perldoc pm_1185726_heredoc_pod.pl]

You can't interpolate variables into the POD text, only the value being assigned to the variable:

$ cat pm_1185726_heredoc_pod.pl our $VERSION = '1.234'; my $str = <<"=cut"; =head2 Some documentation Doco for version: $VERSION =cut print $str;
$ perldoc pm_1185726_heredoc_pod.pl
  Some documentation
    Doco for version: $VERSION
$ perl -wMstrict pm_1185726_heredoc_pod.pl =head2 Some documentation Doco for version: 1.234

Any sample code in the POD may well contain undeclared variables. These will generate "Global symbol "%s" requires explicit package name" compilation errors (when strict is in use) if the heredoc is interpolated.

For these two reasons, I'd suggest <<'=cut'; as the better default option (for code being used in the way shown).

— Ken


In reply to Re^2: Using PerlPod Creatively by kcott
in thread Using PerlPod Creatively by samijoseph

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.