Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the common workarounds for multi-line comments in Perl?

Tags:

comments

perl

This RFC mentions

Unlike many programming languages Perl does not currently implement true multiline comments. This, and the workarounds that are in common use can be problematic. This could be solved by adding a new syntax to allow for comments to span more than one line, like the variation on here-documentation cited below.

What are the common workarounds?

Two techniques I found here are

if (0) {   <comment> } 

and

=pod <comment> =cut 

Are these safe to use? Are there others that work better?

like image 882
Lazer Avatar asked Aug 31 '10 12:08

Lazer


People also ask

How do I comment multiple lines in Perl?

In Perl, multi-line comments are also known as block comments and are defined using “=begin” at the start of the line and “=end” at the end of the comment line, and the other way of using block comments is by using quote operators q{}.

Which symbols are for the multi line comment?

In Python script, the symbol # indicates start of comment line. A triple quoted multi-line string is also treated as comment if it is not a docstring of a function or class.

What is the proper command for multi line comment?

To comment out multiple lines in Python, you can prepend each line with a hash ( # ).


1 Answers

The downside of the "if" solution is that the commented out code still has to be compiled (and therefore still has to be syntax checked).

The downside of your pod solution is that your comments will appear in any documentation generated from the pod.

I use a version of the pod solution that doesn't have that problem. Pod supports =begin format ... =end format paragraphs that are handled by specific formatters. I just invent a "comment" format that isn't handled by any of the formatters I use.

#!/usr/bin/perl  print "This line is executed\n";  =begin comment  print "This line isn't\n";  =end comment  =cut  print "This line is\n"; 
like image 168
Dave Cross Avatar answered Sep 28 '22 17:09

Dave Cross