Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Multi-line comments in perl code?

by cxw (Sexton)
on Apr 03, 2020 at 01:29 UTC ( #11114969=note: print w/replies, xml ) Need Help??


in reply to Re: Multi-line comments in perl code?
in thread Multi-line comments in perl code?

To clarify: as of writing, on Perl 5.28.1 and Perldoc v3.2801:
  • =for comment hides text from perl but not perldoc
  • =begin comment hides text from both perl and perldoc
For example, given foo.pl as follows:
=head1 SECTION =for comment Comment! =cut =begin comment Comment! Number 2 =end comment =cut
  • perl foo.pl produces empty output and no errors
  • perldoc foo.pl produces:
    SECTION Comment!

    which is the text from the =for comment / =cut block.
Therefore, I personally use =begin comment / =end comment / =cut, even though it's a bit tedious.

Replies are listed 'Best First'.
Re^3: Multi-line comments in perl code?
by haukex (Bishop) on Apr 03, 2020 at 06:53 UTC
    =for comment Comment! =cut
    ... produces:
    SECTION Comment!

    That is the correct behavior, your conclusion "=for comment hides text from perl but not perldoc" isn't correct. From perlpod (emphasis mine):

    The command "=for formatname text..." specifies that the remainder of just this paragraph (starting right after formatname) is in that special format.

    Remove the blank line after the =for and the "Comment!" is hidden. The =for still begins a section of POD that needs to be terminated by =cut, so Perl will ignore the entire example you posted.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11114969]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2020-08-09 09:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (54 votes). Check out past polls.

    Notices?